Skip to content

Make InterningBinaryReader pool buffers - #6556

Merged
AR-May merged 3 commits into
mainfrom
exp/interning-binary-reader-pooling
Jun 25, 2021
Merged

AR-May merged 3 commits into
mainfrom
exp/interning-binary-reader-pooling

Conversation

@ladipro

@ladipro ladipro commented Jun 14, 2021 •

Copy link
Copy Markdown
Member

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

ladipro commented Jun 14, 2021

Copy link
Copy Markdown
Member Author

image

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

@rokonec rokonec left a comment

Copy link
Copy Markdown
Member

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)

Comment thread src/Shared/InterningBinaryReader.cs Resolved
Comment thread src/Shared/InterningBinaryReader.cs 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

Area: Performance merge-when-branch-open PRs that are approved, except that there is a problem that means we are not merging stuff right now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InterningBinaryReader+Buffer allocates 16MB opening large solution

5 participants