Before asking my question, can I ask you not to give a lecture on optimization for no reason. Consider the following questions purely academic.
I was thinking about access efficiency between root classes (i.e. often used and often referring to each other) in Java, but this applies to most OO languages ββ/ compilers. The fastest way (I assume) that you can access anything in Java would be a static end link. Theoretically, since this link is available at boot time, a good JIT compiler will remove the need to do any reference lookup to access the variable and point any accesses to this variable directly to the permanent address. Perhaps for security reasons this still doesn't work, but carrying with me ...
Let's say I decided that at startup there are some problems with operations or some arguments that mean that I cannot have a static final link, even if I ran into the problem of creating each class different, since it is recommended that Java classes have static final links to each other. Another reason I might not want to do this would be ... oh, let's just say, for example, that I provide platform-specific implementations of some of these classes .; -)
Now I have two obvious choices. I can find out that my classes know about each other with a static link (to some class of the hub of the system), which is set after building all the classes (during which I claim that they cannot access each other, thereby eliminating the order of operations least during construction). On the other hand, classes could have instances of final references to each other, I must now decide that sorting the order of operations is important or can be assigned to the person passing the arguments - or moreover, by providing platform specific implementations of these classes we want to have a link to each other to a friend.
A static variable means that you do not need to look for the location of the wrt variable in the class to which it belongs, while maintaining one operation. The final variable means that you do not need to search for the value at all, but it must belong to your class, so you save the "single operation". Okay, I know what's really crashing down now!
Then something else occurred to me: I might have static final stub classes, sort of like a crazy interface where every call was assigned to an βimplβ, which could just expand the stub. Then performance will be a double call to the function required to run the functions, and maybe I think you can no longer declare your methods. I suggested that perhaps they could be included if they were properly declared, and then gave up when I realized that I would then have to think about whether references to impl could be made static or final, or .. .
So which of the three will turn out faster ?:-)
Any other thoughts on reducing frequent access overhead, or even other ways to tell performance tips to the JIT compiler?
UPDATE: after hours of testing various things and reading http://www.ibm.com/developerworks/java/library/j-jtp02225.html I found that most of the things you usually look at when setting up, for example C ++ completely exit the window with the JIT compiler. I saw that it starts 30 seconds of calculations once, twice, and on the third (and subsequent) starts it decides: "Hey, you are not reading the result of this calculation, so I do not run it!".
FWIW you can test data structures, and I was able to develop an arraylist implementation that was more efficient for my needs using a micro lens. Access patterns should have been random enough to guess the compiler, but he still decided how best to implement a generic array with my simpler and more customizable code.
As for the test here, I just couldn't get the test result! My simple test for calling a function and reading a variable from a final reference to a non-final object showed more about JIT than JVM access patterns. It is unbelievable that calling the same function on the same object in different places of the method changes the time spent on the FOUR coefficient!
As the guy from the IBM article says, the only way to test optimization is in-situ.
Thanks to everyone who pointed me on this path.