4 ms·
> but you can opt into direct dispatch [in Java] by using the final keyword Most Java JIT compilers will also opt you into direct dispatch automatically where
by chrisseaton 10y ago
> but you can opt into direct dispatch [in Java] by using the final keyword
Most Java JIT compilers will also opt you into direct dispatch automatically where possible, for example a class with no subclasses or an interface with only one implementation.
They'll also opt you into direct dispatch per call site if a given call site has only ever seen objects of a single class.
- KingOfBrian 10y agoThe other cool think about running in a JVM is those optimizations (I believe) are done at run-time -- a luxury that swift doesn't have.
- pjmlp 10y agoSwift can also do it. This is what is called PGO, profile guided optimization. Basically you do several test runs using real use cases, under a profiler and then do a release build using the PGO gathered data as additional input.
- chrisseaton 10y agoYes they have to be done at runtime. In both cases the optimisation could become invalid if you load more classes, so the optimisation also needs to be reversible at runtime. This is an example of how it possible for a JIT to out-perform a static compiler.