CFDocument performance
I’ve been building an app that uses CFDocument to build out some FlashPaper and PDF’s. Everything was working great on my local development box, but when I pushed it to my production box, generation of both the FlashPaper and PDF files was taking forever. Processing time went from 4-5 seconds to 3-6 minutes.
Eventually, I tracked down this newsgroup post, which suggested moving all the CF processing out from between the CFDocument tags. I used CFSaveContent to save my output to a variable, and put just that variable between the CFDocument tags, and my performance problems went away.
The funny thing is, my server wasn’t CPU, Memory or Disk bound. In fact, the stack trace in SeeFusion said that the thread generating the CFDocument was actually waiting. So, that thread was basically sitting there doing nothing for minuets at a time. Hopefully this saves someone else an hour or so looking for the problem and solution.

Was the production server on Standard or Enterprise edition?
Comment by Sean Corfield — February 18, 2007 @ 12:00 am
The production server is running Enterprise, J2EE on JRun. The dev server is running Enterprise (Developer), Standalone.
Comment by Shan — February 18, 2007 @ 12:00 am
Just another note in case you don’t already know:
If you have images in the CFDocument that are being accessed on the same server…make sure to use a "file:/" url to access them instead of a regular HTTP url because it will force a web request to the server for each one instead of just quickly loading the file from disk.
This helped me a lot on a few reports.
Mike.
Comment by Mike Kelp — February 18, 2007 @ 12:00 am
Can’t remember where I heard this but I’ll say it anyway and hopefully someone will tell me if I’m wrong or right.
When styling a documents with CFDOCUMENT always use the @import to include the css. For some odd reason not only does this give better performance, it will take care of the problems most people have with CFDOCUMENT not rendering the style correctly.
Comment by Tony Petruzzi — February 18, 2007 @ 12:00 am
@Tony: the <link> tag for external styles will work too, but again you need to use the "file:///" + path type of absolute URL for the href attribute pointing to the stylesheet.
Comment by Julian Halliwell — February 21, 2007 @ 12:00 am
After a long and tiring effort to track down why cfdocument was performing so badly – and even starting down the path of interacting with iText directly – we pinpointed the performance problems we were having to JPEGs. Yeah… weird.
The short story is we converted any images to png’s (using CFX_ImageCR3) and our performance problems disappeared. In fact, generating a PDF is now 8 or 9 times faster.
Macromedia/Adobe must mangle the jpeg conversion/resample/resize when they add them to the PDF.
Comment by Steve — March 14, 2007 @ 12:00 am
This is beyond stupid of me, but can someone give me an example of adding an image call using the local file reference notation? All I get are X’s when I do a <img src="file://C/… Just figure on a fully qualified file location off the C drive (on Windows) and I can take it from there.
Comment by yetti — November 8, 2007 @ 12:00 am
file:///C:/Users/Shan/Pictures/MyMousey1.jpg
Comment by Shan — November 8, 2007 @ 12:00 am
Thanks Shan!
Comment by yetti — November 11, 2007 @ 12:00 am
file:///C: works great when the files are mapped, but something like:
file:///misc2/images/ does not work. Surely, this is possible without having to map the drive
Comment by Drew — March 19, 2008 @ 12:00 am
Unless the ColdFusion (and maybe IIS, I’m not sure) service is running under a user account that has the mapped drive already assigned, you will not even be able to use mapped drives.
Comment by Shan — March 19, 2008 @ 12:00 am
I just found this blog post through Todd Sharp’s blog post here http://cfsilence.com/blog/client/index.cfm/2007/2/19/Exporting-A-Page-To-PDF-Using-cfdocument
I was having issues with my css not displaying properly (and the pdf taking a long time to create) and saving each section using cfsavecontent and then looping through those inside my cfdocument fixed all those issues.
Comment by matt — September 9, 2011 @ 4:23 pm
[...] CFDocument performance [...]
Pingback by CF911: Are you finding performance problems with CFDOCUMENT? Aware of the important LOCALURL attr.? | Hire Flash Developers — November 19, 2011 @ 8:40 pm