Optimization (idea / question)

Hi :smiley:



I hope i may post in here.

And i hope the thread is not too stupid :confused:

If it is, just move or delete it :slight_smile:





Browsing through jME code, i noticed some "divide by 2" operations.







Uhm, i hope i'm no "know-it-all" when saying that, but I was wondering…



Integer divisions through values that are to the power of 2 (2,4,8, …) can be replaced by the significantly faster shift operation.

Does java replace them automatically when compiling the code? Do you know that?



If not, it could be a nice optimisation to replace all multiply and divide operations that have fixed power-of-2 values (2,4, …, 32, and so on) with shifts and modulo with &





I assume java does that anyway…

But i thought a quick thread would be no harm (except for stealing your time :stuck_out_tongue: )






I was under the impression that the JVM optimized this… but now I can't find any references to back me up.

think the term is inlining - one of the compile options is to take the line numbers etc out of the compiled code, but inling is auto and much is left to teh jvm at run time to optimise. Make sure you have proper logging tools if you take line numbers out - so at least you know what went wrong when it goes tits up.



However it seems that the implementation of the VM works differently per release, in jdk1.1 and 1.2 you could get alot of mileage out of using a -c flag ( javac -c ), but think that has gone now as the compiler compiles so the HotSpot / jvm can optimise. Something to do with java being type safe unlike C or C++



If anyone does a release with jme in - it would make a touch of differnce to use javac -g:none - but make sure you have a decent logger