Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This assumes that the vtables stay in at least L2 cache, which may be a correct assumption for the few hot-path classes. In this regard, I remember how Facebook's android app once failed to build when the codebase exceeded the limit of 64k classes.


No, Java does Class hierarchy analysis and has multiple way not to use v-table calls.

Single site (no class found overriding a method) are static and can be inlined directly. Dual call sites use a class check (which is a simple equality), can be inlined, no v-table. 3-5 call sites use inline caches (e.g. the compiler records what class have been used) that are similar and some can be inlined, usually plus a guard check.

Only high polymorphic calls use v-table and in practice is a very rare occasion, even with Java totally embracing inheritance (or polymorphic interfaces)

Note: CHA is dynamic and happens at runtime, depending which classes have been loaded. Loading new classes causes CHA to be performed again and if there are affected sites, the latter are to be deoptimized (and re-JIT again)


Thats very cool.

Does C++ have any of these optimisations?


Some compilers do some of these optimizations, at least those that not require a JIT and code patching at runtime.

But these optimizations are vastly less critical in C++ where only are minority of functions are virtual.


Thanks, TIL!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: