Search code examples
cachingcoldfusionrailo

Coldfusion/Railo: What's the most efficient way to output file contents - fileRead or include?


While I've always cached database calls and placed commonly used data into memory for faster access, I've been finding of late that simple processing and output of data can add a significant amount of time to page load and thus I've been working on a template caching component that will save parsed HTML to either a file, or in memory, for quicker inclusion on pages.

This is all working very well, reducing some page loads down to 10% of the uncached equivalent - however I find myself wondering what would be the most efficient way to output the content.

Currently I'm using fileRead to pull in the parsed HTML and save to a variable, which is output on the page. This seems very fast, but I'm noticing the memory used by the Tomcat service gradually increasing - presumably because the fileRead operation is reading the contents into memory, and quite possibly, Tomcat isn't removing that data when its finished.

(Side question: Anyone know a way that I can interrogate the JVM memory and find details/stack traces of the objects that CF has created??)

Alternatively, I could use cfinclude to simply include the parsed HTML file. From all the information I can find it seems that the speed would be about the same - so would this method be more memory efficient? I've had issues on the server before with memory usage crashing Tomcat, so keeping it down is quite important.

Is there anyone doing something similar that can give me the benefit of their experience?


Solution

  • It turns out that CFInclude actually compiles the (already rendered in this case) content into a class, which itself has overhead. The classes aren't unloaded (according to CFTracker) and as such, too many of these can cause permgen errors. FileRead() seems to be orders of magnitude more efficient, as all we're doing is inserting content into the output buffer.