[SERVER-82637] Do common sub expression elimination in PlanExplainerImpl::getSummaryStats Created: 31/Oct/23  Updated: 23/Jan/24

Status: Needs Scheduling
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mark Benvenuto Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: neweng, perf-tiger, perf-tiger-handoff, perf-tiger-non-q4, perf-tiger-poc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Operating System: ALL
Participants:

 Description   

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



 Comments   
Comment by Ian Boros [ 14/Nov/23 ]

We might also be able to do this for MatchExpressions.

Generated at Thu Feb 08 06:49:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.