Alex Rivera | Logout

Are Java static calls more or less expensive than non-static calls?

Asked 2010-09-27T15:10:36.653
113

Is there any performance benefit one way or another? Is it compiler/VM specific? I am using Hotspot.

Edit
Report

2 Answers

76

First: you shouldn't be making the choice of static vs non-static on the basis of performance.

Second: in practice, it won't make any difference. Hotspot may choose to optimize in ways that make static calls faster for one method, non-static calls faster for another.

Third: much of the mythos surrounding static versus non-static are based either on very old JVMs (which did not do anywhere near the optimization that Hotspot does), or some remembered trivia about C++ (in which a dynamic call uses one more memory access than a static call).

answered 2010-09-27T15:13:58.517
12

It is unbelievably unlikely that any difference in the performance of static versus non-static calls is making a difference in your application. Remember that "premature optimization is the root of all evil".

answered 2010-09-27T15:13:02.293

Your Answer