What are the differences between static and non-static performance wise?
Essentially, what I'm trying to figure out is what exactly is different between static and non-static allocations, and the performance differences between them. (I know what it does on the surface, but I'm looking for what it does behind the scenes)
There is no significant performance difference between calls to static and non-static methods.
In theory, static method calls might be faster, but the JVM optimizes method calls heavily, so this theoretical difference will most likely not exist in practice.
The theoretical difference is that non-static methods are late bound - the JVM has to figure out at runtime where the code is exactly that needs to be called, because non-static methods might be overridden in subclasses. Static methods are not subject to late binding, so at compile time it's already known what code is to be called exactly.
In practice, the JVM does some very sophisticated things; it analyzes the class hierarchy and converts dynamic method calls (to non-static methods) to static method calls automatically if it can, so that there is no difference at all anymore between non-static and static method calls.
Anyway, do not modify your program to use static methods instead of non-static methods just because you think it helps performance. Doing so is premature optimization. You'd be compromising the design of your application based on some vague feeling that it might help performance. You should only optimize based on evidence - first, determine if your program actually has a performance problem, and if it does, measure with a profiler to find out what the bottleneck is, and concentrate on improving that.
1) Call + return time for static vs. dynamic calls is strongly platform and JVM dependent
2) JVM optimization can be faster than native code for some calls (tested under Windows XP), which came as a complete surprise to me.
Oh yes, for most purposes the way a call is dispatched is insignificant (particularly if any user action is involved). Often calling time is negligible compared with time to execute code in the method body. With fast modern hardware most performance bottlenecks tend to be thread blocking and/or DB related, although maybe not for smartphones. Initial choice of appropriate architecture and data structures is not premature optimization and even if everything has been designed correctly it is still possible to compromise performance so an application does not scale well by choosing complex OOP calls over static methods: http://stackoverflow.com/questions/5038204/apache-commons-equals-hashcode-builder
Here the Guava solutions, or even my similar efforts from a while back (basically some easily accessible code) http://pastebin.com/tAfi8Fm3, show appropriate use of static methods in an OOP environment.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop