Perf: Pool scheduler request buffers #12007
Open
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.
Fixes
Heavy allocations due to scheduler temporary buffers.
Context
Scheduler
allocates a ton of temporary lists / arrays to dump the current list of requests. This is necessary because of the semi-recursive nature of the call stack. As you see here, the largest source of allocationsResumeRequiredWork
can call back into, which would a runtime error without the buffer as the call stack may modify the request list.ResumeRequiredWork
Edit: flubbed that part a bit - it's not methods calling into themselves but multiple methods which take an enumeration calling other methods which modify the target list.
Changes Made
This creates an instance-level
ArrayPool
to share buffers across methods.Specifically this avoids
ArrayPool.Shared
since the implementation differences betweenSharedArrayPool
andConfigurableArrayPool
cause the shared pool to evict the pooled arrays (my guess is that we end up exceeding the threshold due to recursive calls).The
ArrayPool
is thrown out and recreated after each build viaBuildManager.Reset()
, so we're not just holding on to a bunch of extra memory.After this, we end up with:
The runtime cost of the pool is basically trivial: