This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Use ArrayPool for oversized allocations - #39643
Merged
Merged
Conversation
benaadams
force-pushed
the
Pipelines-arraypool
branch
from
July 20, 2019 10:47
214596c to
4c3ac97
Compare
benaadams
force-pushed
the
Pipelines-arraypool
branch
from
July 20, 2019 11:52
4c3ac97 to
923e9a9
Compare
davidfowl
reviewed
Jul 20, 2019
benaadams
force-pushed
the
Pipelines-arraypool
branch
from
July 20, 2019 22:02
07534b8 to
df9abf5
Compare
stephentoub
approved these changes
Jul 20, 2019
stephentoub
approved these changes
Jul 21, 2019
ahsonkhan
reviewed
Jul 24, 2019
| else | ||
| { | ||
| ArrayPool<byte>.Shared.Return(array); | ||
| byte[] poolArray = (byte[])_memoryOwner; |
There was a problem hiding this comment.
Could _memoryOwner ever be anything else other than IMemoryOwner<byte> or byte[]?
davidfowl
approved these changes
Jul 30, 2019
Member
|
This will make dotnet/aspnetcore#12632 a lot harder. |
Member
|
Not really, we need need to expose an option to clear on return. |
Member
|
|
Member
|
Sounds like a reason to do this https://github.com/dotnet/corefx/issues/25843 |
picenka21
pushed a commit
to picenka21/runtime
that referenced
this pull request
Feb 18, 2022
* Use ArrayPool for oversized allocations Commit migrated from dotnet/corefx@e7134de
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
When Pipelines allocation is larger than the max pool size; use ArrayPool, rather than
new byte[]Oversized allocations are useful in situations where you want to minimize syscalls; for example
IHttpSendFileFeaturein Kestrel its faster to read from a file directly into the Pipe (zero copy(ish)) with a larger buffer size (16kB+) than it is to read the smaller chunks the Pool allows, however if its allocating an array each time than this more than offsets that advantage.Currently with the smaller block sizes it is more performant to read a file chunk first into a larger array pool buffer (lower syscalls), then copy that file into many smaller Pipe buffers.
It makes more sense to just read into the Pipe directly and avoid the additional copy.
It is unfortunate that this approach is currently slower; as you either have to increase file read calls using the smaller buffers, or allocate a new array for each read with a larger buffer.
This PR makes direct file reads into the Pipe a non-problematic option.
/cc @davidfowl @Tratcher @stephentoub
Resolves https://github.com/dotnet/corefx/issues/39640