JIT optimization works so well because they optimize what your code actually does, rather than what it can do in different cases.
It is even possible that the JIT code is different from different launches due to different input data. Or even this can be retested more than once when circumstances change.
In other words: without real data, the JVM will not do good performance optimization code. (i.e. it can only perform "static" optimizations)
But in the end, if you get such a high improvement (30x is a lot!), It is likely that he either
- not code, but something else (e.g. file caches or databases)
- very suboptimal code at the source level. (e.g. some heavy calculations that might come out of tight loops)
EDIT:
Looking at your code in a large loop on Literas.prepareLiteras() , you constantly call path.contains(p) with different points, but in the same way. SimplePath.contains() creates a bounding form every time it is called, so you create the same form again and again. This is a prime example of what needs to be pulled out of the inner loop.
I donβt think JIT can optimize this whole method, but in some extreme cases it can convert getShape() to something specialized for one path and recompile for the next path again. Bad use of JVM smarts, huh ??
Javier
source share