Optimize Record._elements to not duplicate VectorMap if possible (backport #4254) #4265
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.
The code is a little janky, but it is a massive reduction in memory use.
For a typical Bundle with 7 UInt fields, this reduces the memory footprint from 1992 bytes to 1552 bytes (the duplicate VectorMap of only 7 elements is 440 bytes!), a 22% reduction. Combined with my other recent performance improvement PRs (#4251, #4252, #4253 but excluding #4242), this 1992 bytes is reduced to 1424 for a total reduction of 28.5% memory use for this typical Bundle with 7 UInt fields.
I suspect we can do better by getting rid of any Map here at all and instead just use an
Array[Data]
(where the String names of the fields are stored in the children Data themselves as they are already stored there). Whereas the VectorMap of 7 elements is 440 bytes, an Array of 7 elements is 48 bytes.That being said, this is a much simpler change that imparts a huge benefit so is worth it in the meantime.
Contributor Checklist
docs/src
?Type of Improvement
Desired Merge Strategy
Release Notes
This reduces memory use of a typical bundle by 20%.
Reviewer Checklist (only modified by reviewer)
3.6.x
,5.x
, or6.x
depending on impact, API modification or big change:7.0
)?Enable auto-merge (squash)
, clean up the commit message, and label withPlease Merge
.Create a merge commit
.This is an automatic backport of pull request #4254 done by [Mergify](https://mergify.com).