Skip to content
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

Make InterningBinaryReader pool buffers #6556

Merged
merged 3 commits into from
Jun 25, 2021

Conversation

ladipro
Copy link
Member

@ladipro ladipro commented Jun 14, 2021

Fixes #3954

Context

The Buffer class is 100 kB (40 for characters and 60 for the byte array) and it is being allocated a lot, easily in the order of tens of thousands of instances per build. OOM crashes are often blamed on such allocations.

Changes Made

  1. Made the byte array allocation lazy since in many scenarios it ends up not being used.
  2. Implemented a trivial Buffer pooling which eliminates >97% of allocations.

Testing

  • Existing unit tests.
  • Experimental VS insertion.

Notes

Opted for a 1-element static cache to keep the last used Buffer around. This works very well given MSBuild's single-threadedness and keeps the code simple and policy-free.

@rainersigwald rainersigwald added this to the 17.0 milestone Jun 14, 2021
@ladipro
Copy link
Member Author

ladipro commented Jun 14, 2021

image

RPS is showing ~6% improvement in allocated devenv bytes during rebuild. Will address the failing unit test shortly.

Copy link
Member

@rokonec rokonec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider commenting static internal ITranslator GetReadTranslator(Stream stream, SharedReadBuffer buffer) and explain consequences and behavior of null buffer passing.
NIT: I would recommend introducing static internal ITranslator GetReadTranslatorUsingPooledBuffer(Stream stream)

src/Shared/InterningBinaryReader.cs Show resolved Hide resolved
src/Shared/InterningBinaryReader.cs Show resolved Hide resolved
@Forgind Forgind added the merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. label Jun 21, 2021
@AR-May AR-May merged commit 9fc3fa5 into main Jun 25, 2021
@ladipro ladipro deleted the exp/interning-binary-reader-pooling branch October 25, 2021 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now. performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InterningBinaryReader+Buffer allocates 16MB opening large solution
5 participants