v2.2: Optimize AppendVec / BufferedReader buffer sizes and alloc strategy (backport of #5457) #5487
+198
−107
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.
Problem
BufferedReader
instances allocate significantly more memory than is optimal. This creates significant dropping pressure and slows down file reading from disk.Summary of Changes
This adjusts
BufferedReader
instances to use 4KiB stack buffers for reads that don't require account data. The instance that does require account data starts with a 1MiB heap buffer and will resize once to worst case (~10MiB) account data size if an account is encountered that doesn't fit in the 1MiB buffer. This is optimized for the typical case where most accounts are token accounts of roughly ~300b.BufferedReader
had to be made generic to support both stack and heap allocated buffers, which adds a small amount of complexity, but gives us the significant advantage of not having to heap allocate every instance.This is an automatic backport of pull request #5457 done by [Mergify](https://mergify.com).