Stress-testing Control Structures for Dynamic Dispatch in Java
Created on 2020-08-19T21:16:04.492451
- Up to 13.7% of a C++ program's time is spent in vtable dispatch.
- When there are 2-8 type candidates to dispatch to, one can avoid using a vtable for greater performance.
- Java uses a "virtual method table" by default.
- But you can also use "binary tree dispatch."
- You could also use switch statements.
Binary tree dispatch is implied to be faster, though likely only as long as you do not have too many targets to choose from. The code grows logarithmically for each destination it has to select.