-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SelectExpression.VisitChildren optimizations #17594
Conversation
Do not allocate and copy the different components if visitation hasn't changed anything. Affects #17455
LGTM as long as test pass. Requested review from Andriy just in case. |
|
||
changed |= projection != item; | ||
if (newProjections != _projection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (newProjections != _projection) | |
if (changed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in the case below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful, changed
tracks if any component of the SelectExpression was changed, including previous unrelated components. This change seems like it would make us falsely go into the condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it should be fine for these two cases, since changed
is not mutated before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see... I'd rather leave it like this - who knows if we'll shift the code fragments around and this would become invalid... There's no real gain in replacing a single reference comparison with a bool check...
Profiling the scenario in #17455 showed that SelectExpression.VisitChildren was a major compilation perf hotspot (own time, not including child calls). This PR changes the logic to only allocate new data structures and copy if a Visit actually returned a different result.
This reduced the time for #17455 from 22 seconds to 15 on my machine. Memory allocated notably goes down from 61.86MB to 12.17MB.
Also added a compilation micro-benchmark which does three joins, here are the results. Note that #17455 includes 6 results and so the difference is considerably more significant.
Before
After