auto-optimization of small, known loops

I have a generically written geometry tree class, which can be instantiated for 1 or more dimensions (2 yields a quadtree, 3 a octtree, …).

The number of dimensions is specified in the constructor, and assigned to a final instance variable.

Obviously, most geometry manipulations need to loop over the number of dimensions. These loops are mostly tight and straight-forward, and also straight-forward for me to override and optimize in an octtree subclass later on.

I’m curious though regarding the intelligence of today’s dynamically optimizing VMs… Are they able to unwind loops over small, final variables? Especially when the loops contain straight-forward, easily inlineable code?

/ Chris

Seeing as it’s all smoke & mirrors these days and no-one can give you a straight answer, not even Sun VM engineers, you have no choice but to write a specialised version and compare the performance with the unspecialised version. And, of course, tell us what the difference is :slight_smile:

Cas :slight_smile:

[quote]you have no choice but to write a specialised version and compare the performance with the unspecialised version
[/quote]
…or go down to the JVM source and check the assembly code generated by the compiler (btw, there is really a big difference in that between client and server VMs).

Yuri

The former method may be easier :slight_smile:

Cas :slight_smile: