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

Streamline rent/return on ArrayPool #55710

Merged
merged 2 commits into from
Jul 16, 2021
Merged

Conversation

stephentoub
Copy link
Member

A variety of tweaks to reduce overheads:

  • Stop storing and using a _bucketArraySizes. It's cheaper to recompute the shift on each use than it is to index into the array (with a bounds check). Plus less memory.
  • The 99% case is renting a positive length for pooled array sizes (especially now that we've bumped the limit up to a gig). Move the checks for lengths <= 0 to after the check for whether the length is poolable.
  • Move arrays/counts into locals to enable the JIT to eliminate some bounds checks.
  • Use ThrowHelpers where we already have them
  • Move non-generic helpers out of generic class into Utilities
  • Consolidate buffer allocation in Rent to a single line
  • Reorganize TLS checks to be as early as possible
  • Use FastMod instead of % in per-core stacks
Method Toolchain Mean Error StdDev Ratio RatioSD Code Size
PopPush \main\corerun.exe 17.58 ns 0.357 ns 0.334 ns 1.00 0.00 2,221 B
PopPush \pr\corerun.exe 16.64 ns 0.021 ns 0.019 ns 0.95 0.02 1,980 B
PopPushMulti \main\corerun.exe 1,127.07 ns 7.303 ns 6.098 ns 1.00 0.00 2,167 B
PopPushMulti \pr\corerun.exe 1,082.29 ns 3.208 ns 2.679 ns 0.96 0.01 1,875 B

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@stephentoub stephentoub added this to the 6.0.0 milestone Jul 15, 2021
@ghost
Copy link

ghost commented Jul 15, 2021

Tagging subscribers to this area: @GrabYourPitchforks, @dotnet/area-system-buffers
See info in area-owners.md if you want to be subscribed.

Issue Details

A variety of tweaks to reduce overheads:

  • Stop storing and using a _bucketArraySizes. It's cheaper to recompute the shift on each use than it is to index into the array (with a bounds check). Plus less memory.
  • The 99% case is renting a positive length for pooled array sizes (especially now that we've bumped the limit up to a gig). Move the checks for lengths <= 0 to after the check for whether the length is poolable.
  • Move arrays/counts into locals to enable the JIT to eliminate some bounds checks.
  • Use ThrowHelpers where we already have them
  • Move non-generic helpers out of generic class into Utilities
  • Consolidate buffer allocation in Rent to a single line
  • Reorganize TLS checks to be as early as possible
  • Use FastMod instead of % in per-core stacks
Method Toolchain Mean Error StdDev Ratio RatioSD Code Size
PopPush \main\corerun.exe 17.58 ns 0.357 ns 0.334 ns 1.00 0.00 2,221 B
PopPush \pr\corerun.exe 16.64 ns 0.021 ns 0.019 ns 0.95 0.02 1,980 B
PopPushMulti \main\corerun.exe 1,127.07 ns 7.303 ns 6.098 ns 1.00 0.00 2,167 B
PopPushMulti \pr\corerun.exe 1,082.29 ns 3.208 ns 2.679 ns 0.96 0.01 1,875 B
Author: stephentoub
Assignees: -
Labels:

area-System.Buffers

Milestone: 6.0.0

@stephentoub stephentoub reopened this Jul 15, 2021
- Stop storing and using a _bucketArraySizes.  It's cheaper to recompute the shift on each use than it is to index into the array (with a bounds check).  Plus less memory.
- The 99% case is renting a positive length for pooled array sizes (especially now that we've bumped the limit up to a gig).  Move the checks for lengths <= 0 to after the check for whether the length is poolable.
- Move arrays into locals to enable the JIT to eliminate some bounds checks.
- Use ThrowHelpers where we already have them
- Move non-generic helpers out of generic class into Utilities
- Consolidate buffer allocation in Rent to a single line
- Reorganize TLS checks to be as early as possible
- Use FastMod instead of % in per-core stacks
@stephentoub stephentoub merged commit d4dcde1 into dotnet:main Jul 16, 2021
@stephentoub stephentoub deleted the arraypoolslim branch July 16, 2021 14:49
@ghost ghost locked as resolved and limited conversation to collaborators Aug 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants