While reading Jack Shirazi’s ‘Java performance tuning’, I came across the following statement:
“Instance and static variables can be up to an order of magnitude slower to operate on when
compared to method arguments and local variables.”
Is this still applicable to Java 6/7? And if yes, what are the reasons behind it? (He explained something about having special bytecodes for accessing local variables/parameters but I did not understand it).
The key words here are can be. The issue is that locals and params (which are essentially a flavor of locals) may be in registers, while instance and static variables will ultimately end up in memory (they would get into registers for the time necessary to operate on them, but eventually back to the memory they go).