Chris wrote:
> I have some super time-critical code, where I'm doing a lot of integer math
> across very large arrays. Performance isn't as good as it could be. I'm
> wondering if the fact that Java does bounds checking on every array access
> could be slowing things up.
>
> Question: is the bounds-checking performed in bytecode, or in native JVM
> code? I'm thinking that if it's in bytecode, I could generate a little
> custom code that turns it off for those time-critical methods.
A native compiler (whether JIT or AOT) will remove the checks when it
is safe to do that. So you should write your code in a manner that
enables the compiler to remove checks. One rule of thumb is: "use 'for'
loops and do not change the loop variable anywhere inside the loop
body". I.e. your loops must be equivalent to the Pascal/Modula FOR
statement. Then, you better not call any methods from the loop body
except when you are sure they will be substituted inline by the
compiler. An example is final set/get methods.
Also, the bytecode supplied to the JVM must not be optimized. So use
the standard javac compiler to produce bytecode, and never ever use any
bytecode obfuscators/optimizers.
Finally, check out Excelsior JET and Excelsior's performance tuning
services:
http://www.excelsior-usa.com/jet.html
http://www.excelsior-usa.com/services30.html
The current version, Excelsior JET 3.7, is not very good at doing
floating point math, but for integer arrays it should be a killer.