Fanout: reduce allocation related to staleness tracking #2405
+32
−20
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.
PR Description
We typically send a lot of data through appenders (fanout and interceptor), but we always allocate 0-size slice for
the staleness trackers. This results in high allocation in these methods:
In this change I'm capturing how many staleness trackers we had previously and use that value to allocate the array, which results in 50% less allocation in the entire
.Append
chain.There is some more allocation in the constructor now, but overall it is a reduction because the slice doesn't need to grow (in most cases):
The gains will be even larger the more Fanouts and Interceptors are used in the pipeline.
Which issue(s) this PR fixes
Notes to the Reviewer
PR Checklist