4 ms·
The one I've heard most about in Java is single-implementation devirtualization. Since Java loads dynamically at the class level, it knows exactly which impleme
by jdmichal 7y ago
The one I've heard most about in Java is single-implementation devirtualization. Since Java loads dynamically at the class level, it knows exactly which implementations of an interface or class hierarchy are in use. It has to maintain this information in the class loaders anyway, so this is almost free. However, it allows for some pretty aggressive devirtualization by only compiling for known loaded types and trapping the rest. In my experience, especially around things like interfaces defining module contracts, there tends to only be one implementation in play during normal runtime, meaning that the interface becomes zero-cost. And it doesn't even have to track new implementations loading. It just leaves the optimization there until it has proof via the trap that it must recompile.