Hey, that is undocumented!

Posted At : May 15, 2008 7:36 PM | Posted By : Dave
Related Categories: ColdFusion 8,General

While working on a new application I ran into an interesting issue. The solution to the issue was complex, and I was not pleased with the result. The solution was far from elegant or streamlined. The code was totally bloated, but for necessary reasons. I reworked the code a few times and made it more compact but the end result was still not pleasing.

I bet you are saying, "If it works leave it alone" or something like that. If so I would tend to agree. However, I am one of those people that would spend an hour coding to squeeze out 500ms of processing. I am very critical of what I write and do my very best to make performance paramount.

After leaving the code sit for a few days I want back to it with a clear head. I then started poking around the net looking for ideas. I then started playing around using underlying java objects to make the code better. I then found some undocumented functions in CF that made the code even better.

This is where I hit a crossroad. I was faced with a very perplexing issue. Do I, A: Leave the code alone knowing I could make it better or B: Use some undocumented functions and get the result I was looking for. After pondering it for a while I ended up with option B.

Now, why is this such a big deal? There are many reasons this could be a potential issue. For starters any issues that arise by using an undocumented item are not supported. You can find people that can help you but that would be a very short list. Also, potentially the level of skill required to work in it after you are done could a problem. Then there is the potential that the undocumented item becomes unavailable after an upgrade. This is probably the biggest reason not to do it.

On the other hand, undocumented things usually fill a gap. They provide new functions and tools that are generally unavailable. For instance "queryname.isFirst()" does the same thing as "query.current_row EQ 1". Obviously the undocumented function is more elegant and probably faster. This is just one item in a long list of undocumented items in CF.

Every situation is unique and has unique challenges. Those challenges should be evaluated separately. Do what works for what you are doing. The important thing is to understand the risks involved. If the reward outweighs the risk then go for it. Just be prepaired for the fact that the risk may not pay off.

till next time.

--Dave

Comments
I think you mean "query.currentRow EQ 1" :)
# Posted By Ed | 5/16/08 12:33 AM
Care to share your solution?
# Posted By Andy Matthews | 5/16/08 4:22 AM
I can tell you right now, ColdFusion FORCES you to make no differentiation between ColdFusion strings and Java strings. You actually can't create a Java string and have it be any different than a ColdFusion string. So, at the very least, you should feel free to use Java string methods to your hearts content.
# Posted By Ben Nadel | 5/16/08 5:05 AM
I think the answer is the good old 'it depends'. There are some that say *never* use undocumented features, there are others who love hacking things up for bits of performance gains. However, each and every case should be evaluated for 'risk vs. reward'. If you can gain 500ms by doing something in an undocumented way, then I'd say that *may* be worth the risk. But I think we all owe it to ourselves and the community to speak up to Adobe and say 'hey - look at this - it's XXXms faster by doing it this way!' -- and if it is true, then Adobe should possibly look at re-tooling the underlying algorithims to take advantage of that performance increase. Post some code so we can discuss further, otherwise it's all just hypothetical. I'm a 'concrete' person - I like to discuss real cases where I can see code, otherwise it's all just conjecture to me.
# Posted By todd sharp | 5/16/08 5:48 AM
Dave, this inspired me to put down some thoughts:

http://www.bennadel.com/index.cfm?dax=blog:1230.vi...
# Posted By Ben Nadel | 5/16/08 6:35 AM
If I was able to share the code I would have. However, the code itself is not the point of the post. The point of the post was merely me putting down the thoughts in my head about the subject in general.

@Ben - I read your blog entry. You are a much better word smith than I. Very well said.

@Todd - I did not intend to say that by using undocumented items I shaved 500ms off the code. It was more of an exaggeration. I was just explaining my tenacity with respects to writing performance centric code.

--Dave
# Posted By Dave Ferguson | 5/16/08 7:35 AM
I'm curious, but why write performance-centric code? There are quite a few tricks (mostly common-knowledge) to not coding performance nightmares into applications that are easy to take into consideration, but I would have to say I write maintenance friendly code first, performant code second. I would argue that it is a lot easier to optimize a bug-free application for performance rather than bug-fix a performance optimised application.

There are many potential bottlenecks in an application, and it usually only 1 or 2 that have significant impacts on application performance. If you optimise your application performance after it is code-complete, you can focus on only the bottlenecks that really matter and will produce the biggest improvement. Over-engineering for performance potentially wastes your development time for minimal savings whilst maybe wasting someone else's time when they try to maintain the code.

Is the performance savings in using an undocumented feature worth the risk of complicating an upgrade later down the track? Clearly it depends on the performance increase and the application, but I maybe this is difficult to determine until later, when the overall performance and resource usage of the application can be more fairly judged. I'm always very skeptical when I find myself wanting to trade off against future maintenance, because it does often bite me when I do not keep it in the forefront of my mind.

Make sense? I might blog about this issue - If so I will leave a note.
# Posted By Ben Davies | 6/17/08 8:34 PM
very thanks for you..
# Posted By Oyun | 11/26/08 3:13 PM