mapstr: optimyze Clone#64
Merged
cmacknz merged 1 commit intoelastic:mainfrom Jun 28, 2022
florianl:flo-mapstr-clone
Merged
Conversation
Reduce the ammount of allocations when using Clone(). name old time/op new time/op delta Clone-8 8.95µs ± 0% 5.51µs ± 0% ~ (p=1.000 n=1+1) name old alloc/op new alloc/op delta Clone-8 4.99kB ± 0% 2.50kB ± 0% ~ (p=1.000 n=1+1) name old allocs/op new allocs/op delta Clone-8 64.0 ± 0% 33.0 ± 0% ~ (p=1.000 n=1+1)
Collaborator
cmacknz
approved these changes
Jun 28, 2022
Member
cmacknz
left a comment
There was a problem hiding this comment.
Nice! There will need to be a follow up PR in beats to pick up this change, I can tag it after we merge this.
Member
|
Beats PR incorporating this change: elastic/beats#32161 |
cmacknz
added a commit
to cmacknz/elastic-agent-libs
that referenced
this pull request
Jun 30, 2022
The bug was introduced by elastic#64. Add a test to catch the bug that slipped through.
cmacknz
added a commit
that referenced
this pull request
Jun 30, 2022
* Fix bug introduced by mapstr optimization. The bug was introduced by #64. Add a test to catch the bug that slipped through. * Update changelog for 0.2.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reduce the ammount of allocations when using
Clone().Type of change:
EnhancementWhat does this PR do?
When profiling
filebeatI have noticed heavy use ofMapStr.Clone()operations that resulted in manyruntime.mallocgc(). Looking at the code, I did see that the resultingMwas not sized properly even if its resulting size is known in advance.As the added benchmark demonstrates, there is a noticeable reduction of memory allocation even for small
MapStrwhen usingClone()now.Why is it important?
Incremental resizing of
MapStr, as it is done whenMapStris not properly sized in advance, will give the garbage collector more work to do. So this change does not only reduce the number of allocations but also reduces the work that needs to be done by the garbage collector.Checklist
As there is only a minimal code change, I have skipped this one. Please let me know, if you want more comments.
testsbenchmarks that prove my fix is effective or that my feature worksCHANGELOG.mdFor users of this package there is no "visible" change. So I did not add something.