IT lexicon › Programming › Devirtualization

Devirtualization

Programming På svenska → Updated: 2026-11-05

Replacing a virtual call, which looks up its target in a table at run time, with a direct call once the compiler can prove which method will actually run.

The lookup itself is cheap. The expensive part is that an indirect call can't be inlined, which shuts the door on everything inlining would otherwise unlock. Statically it works when the type is known at the call site, when the class is marked final, or when link-time optimisation sees the whole class hierarchy and finds only one implementation.

JIT compilers can guess. HotSpot and V8 watch which types actually flow through a call, emit a direct call guarded by a cheap type check, and fall back if the guess turns out wrong. GCC gained a speculative variant in 2014 built on the same idea, minus the live profile. In C++ code with deep inheritance hierarchies, the payoff often beats any other single optimisation.

← Back to the lexicon