Ben Forta, Allaire evangelist, presented "Optimizing ColdFusion 4 Applications" at the Toronto CF User Group meeting last night. Here's a summary of some of his strategies.

Use the Database

According to Ben, the single biggest culprit in poorly performing CF websites is the CF programmer trying to do the database's job. Because CF is a runtime interpretive environment, you should use the database wherever possible, particularly for For example, let the database default the current time into a timestamp column when inserting a new record, rather than using CF's Now() function and converting it to fit the database input datetime format. Another example? Use a trigger to return a database auto-generated value rather than a SELECT MAX() query to find the value that was just created.

Reuse Code

Use CFINCLUDE and Custom Tags (a powerful "black box" feature, especially in CF4+), to modularize your code and make it easier to maintain and optimize. Custom Functions will probably be available in CF5.


Hard drives are "the only component in your computer with a mean time between failures actually stamped on them," said Ben. "They will disappear, but not any time soon." Cold Fusion supports three types of caching:
  1. page level caching -- CF opens and reads a cfm page, translates it into P-code, and keeps it in cache; bump your 1024K default high enough to hold all the cfm pages in your site (the memory is not allocated, it's just an upper limit).
  2. page output cache -- use CFCACHE to cache dynamic output to simulate static pages (a great example is evolt's own FAQ page at
  3. query result caching -- "How many times do you want to go to the database to get state codes to populate a drop down list? This being Canada, when was the last time you added a new province?" Ben asked. Many in the audience immediately shouted "Last April!" Not missing a beat, Ben came back with "And the time before that?" Another example where query result caching should be utilized is for "next N" queries, which otherwise would re-return the entire result set every time.
Ben also urged greater utilization of database stored procedures, but cautioned that CF cannot handle return codes, output parameters, or multiple result sets for one query.

The evening concluded with a question-and-answer session briefly covering Spectra, JRun, and WDDX. If you ever get a chance to catch a Ben Forta presentation, I recommend it highly.

rudy limeback