|
Currently PlanExplainerImpl::getSummaryStats makes repeated calls to stageType() which is a virtual function. Since this is a virtual function, the compiler cannot inline the call and also must repeat the call each time it is called as written in the code. A savings of a few instructions and a few function calls can be done by storing the result of this function call in a local variable.
Current Code
if (STAGE_IXSCAN == stages[i]->stageType()) {
|
...
|
} else if(STAGE_COUNT_SCAN == stages[i]->stageType()) {
|
...
|
Suggested Improvement
auto stageType = stages[i]->stageType();
|
if (STAGE_IXSCAN == stageType) {
|
...
|
} else if(STAGE_COUNT_SCAN == stageType) {
|
...
|
POC: https://github.com/10gen/mongo/commit/3c3d7ae8ec93db1ebbb3da3f97f57235c71f5f1e#diff-86a236f1dd8112311222323d8951b5d46eda648735fca2d28a50e1eb9d0bd30e
|