|
|
|
|
|
by hyperpape
3347 days ago
|
|
While I'm inclined to suspect that non-virtual by default is better from a design perspective‡, don't assume the point about performance is overwhelming. HotSpot has done devirtualization for a long time. You can detect not only when a method is never overridden, but also when it's never overridden at a particular call site. A virtual method that's never overridden can sometimes have no extra overhead, while a virtual method that is overridden may have sufficiently small overhead that it rarely matters. http://insightfullogic.com/2014/May/12/fast-and-megamorphic-... ‡ I've used non-OO languages, but never an OO language without virtual by default. |
|
At the end of the day, the fastest code is one that doesn't have to run.
HotSpot is an impressive technology but the optimizations it has to do to overcome Java's design really only pay for themselves in most frequently executed code paths and only after some time to gather necessary info to perform the optimizations.
It's ok for long-running server code but not good for, say, short-lived command-line program.
Or to put it differently: a language that has perf-friendly design, like Go, matches Java's speed with 10% of engineering time and resources spent on the compiler and optimizations. Perf friendly design means it has to do 10% of the work to achieve the same end result.