Lucee has a hidden feature to force the compiler to externalise strings from class files, this can reduce the size of class files a lot and because of that the memory footprint of a running application.
Please have in mind that the removal of the PermGen space in Java 8 not really has influence on this, moving in java 8 from permgenspace to meta memory is just change how the memory is handled, but it does not free memory in any way.
Below you can find a detailed description of this feature with installation and configuration instructions.
Question is, should we enable this feature with Lucee 5 by default and make it visible in the admin?
Explanation
When a CFML template is executed, Lucee generated a java class file of that template, this class files includes everything of the CFML template including all texts.
Class files in Java are loaded to the PermGenSpace (short: PGS) memory portion. So having a lot of CFML files executed can mean that the PGS is filled up and runs out of memory. To avoid this, Lucee comes with a hidden feature to externalize string of a certain size to an external file, that files then only get loaded into the memory when needed and it is removed from memory afterwards (with some caching mechanism).
This feature reduces the footprint of classes, but slows down execution a little bit, because it has to load this external resources. Impact on performance normally is less than 1% of the overall execution time depending on the actual value of the setting (see “Configuration” for details).
Installation
- stop Lucee
- add the (or extend) the following tag in the body of the root tag of the xml file {lucee-server}/lib/ext/context/luee-server.xml
<compiler externalize-string-gte="100"/>
- delete all “cfclasses folder” (I will make sure that this step is no longer necessary in future versions)
- start Lucee
Configuration
In the example above, all text that are bigger or equal than 100 character are moved to an extrernal file.
Having the text in a external file slows down the execution of a template a little bit, but it does not matter if only one portion is externalized or multiple, then the file is only loaded once when executed and holds all portions of the externalized texts of one class.
So what the right value is for this setting is hard to say, bigger number, less text is externalized but the code run faster. So best is to start with 100 and then see what the effect is, means check how big the .txt
files in the cfclasses
folder are in comparison to the .class
files.
Every change on this value makes it necessary to delete all cfclasses
folders.