-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
*: reduce ResetContextOfStmt() and NewRuntimeStatsColl() object allocation #26007
Conversation
[REVIEW NOTIFICATION] This pull request has not been approved. To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Each time we eliminate a allocation from the list, we can reduce the allocation by 2%-1%, and the performance improve a bit. |
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.
Rest LGTM
sc.RuntimeStatsColl = execdetails.NewRuntimeStatsColl() | ||
// In ExplainFor case, RuntimeStatsColl should not be reset for reuse, | ||
// because ExplainFor need to display the last statement information. | ||
if _, ok := s.(*ast.ExplainForStmt); ok { |
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.
Now I do not reset RuntimeStatsColl
when the statement is ExplainFor
, the test passes.
// Reuse the object to reduce allocation when *RuntimeStatsColl is not nil. | ||
func NewRuntimeStatsColl(reuse *RuntimeStatsColl) *RuntimeStatsColl { | ||
if reuse != nil { | ||
for k := range reuse.rootStats { |
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.
Reuse map is cheaper than create a new map object.
Go compiler optimize this cleanup code pattern to a clearmap()
function.
Temporary close it. |
What problem does this PR solve?
Reduce prepared point get object allocation, see #25573
Set
EnableCollectExecutionInfo
config to false can reduce the allocation from 101 allocs/op to 89 allocs/op, it does have some performance impact on the point get case @crazycs520What is changed and how it works?
Reduce the allocation rate by 2%
Before:
BenchmarkPreparedPointGet-16 3945436 9160 ns/op 7830 B/op 101 allocs/op
After:
BenchmarkPreparedPointGet-16 4047969 8913 ns/op 7038 B/op 99 allocs/op
What's Changed:
Avoid allocating StatementContext every time, reuse it.
Avoid allocating RuntimeStatsColl every time, reuse it.
How it Works:
Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Release note