About this question

Virtual Dispatch Cost

Hard · Code Analysis · Quant Trader interview question · C++, virtual functions, performance, latency, optimization

In a latency-critical trading system, you're optimizing a hot loop that processes incoming market data. This loop frequently calls a virtual function process() on objects pointed to by a base class pointer. You need to understand the performance implications of this virtual dispatch mechanism. Consider the following overheads: 1. vtable lookup: The process of finding the correct function to call based on the object's actual type. 2. Cache miss potential: The chance that the vtable or the funct