OS: Linux
Java Version: 11.0.11
Tomcat Version: 8/9
Lucee Version: 5.x and 6.x
I recently wrote a .cfm module that does enormous amounts of floating point math very quickly. It spawns multiple threads, each of which handles a subset of the total calculations, and they all run in parallel and saturate the machine’s CPU cores so the overall task gets done very quickly.
Collectively it’s at least a hundred million or more floating point operations, and due to the core-saturating parallelism they all happen very VERY quickly.
Under Lucee 5.x, it works beautifully and shockingly fast, and memory use (heap and stack) is so tiny it doesn’t even register on the admin page’s realtime memory usage graphs. That’s because Lucee 5.x uses the “double” type, which is a mutable primitive type held on the Java stack, and the countless millions of changes to the working variables are done IN-PLACE, with NO new memory being allocated for new copies of the variables.
Under Lucee 6.x, my process dies with an out-of-heap-memory error, after spiking the heap memory use up to the moon. That’s because Lucee 6.x is no longer using “double” but instead “BigDecimal”, which is an immutable non-primitive held in the Java heap, and every one of those millions of changes to the working variables makes NEW copies which eats up the entire heap quickly.
Apparently the garbage collector can’t keep up with this, and the program crashes (with only 1 of its threads, the lightest-workload one, having had time to finish). A minute or so after the module crashes and dies with an out-of-heap-memory exception, the garbage collector seems to run, because the Admin’s heap graph drops back down to near-zero.
In addition to this fatal crashing problem from insane heap memory use, the “BigDecimal” floating point operations are much slower than “double” ones.
I know “BigDecimal” is more accurate, but what I’m doing does not require that extra accuracy at all. These numbers represent just estimates, no extreme precision is needed, in fact the precision of “double” is already far more than enough for this application.
I realize that the majority of Lucee code probably isn’t extreme like this and won’t be significantly harmed by the double-to-BigDecimal switch, but some (like mine) is hugely harmed by it.
Can we please get one or more of the following?
-
Admin (unified simple-mode admin, server admin and/or web admin) setting telling Lucee to use the “double” instead of “BigDecimal” for floating point variables?
-
More granularly, a per-template setting (via the cfsetting tag maybe?) to tell Lucee to use “double” for floating point variables for this specific module only?
-
Most granularly of all, a way to declare only certain variables (the ones that change many millions of times) to be “double” not “BigDecimal”?
If not, I’ll have to stick with Lucee 5.x indefinitely, or switch to another language entirely, which I don’t want to do.
Thanks!