Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Use local array in ConcurrentQueue<T> for small perf improvement#21192

Merged
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:cqlocal
Nov 27, 2018
Merged

Use local array in ConcurrentQueue<T> for small perf improvement#21192
stephentoub merged 1 commit into
dotnet:masterfrom
stephentoub:cqlocal

Conversation

@stephentoub
Copy link
Copy Markdown
Member

Enqueue/TryDequeue/TryPeek are all repeatedly accessing the same array from a readonly field. Changing them to instead access that same array but from a cached local results in an ~10% throughput boost on a microbenchmark that does uncontended reads/writes of objects from/to the queue. (I also tried using a ref local to point directly to the target slot in the array, but that actually resulted in a measurable regression.)

cc: @kouvel, @benaadams

Enqueue/TryDequeue/TryPeek are all repeatedly accessing the same array from a readonly field.  Changing them to instead access that same array but from a cached local results in an ~10% throughput boost on a microbenchmark that does uncontended reads/writes of objects from/to the queue. (I also tried using a ref local to point directly to the target slot in the array, but that actually resulted in a measurable regression.)
@benaadams
Copy link
Copy Markdown
Member

benaadams commented Nov 26, 2018

I think this will be a common regression

From "RyuJIT bounds checks not eliminated for readonly arrays" https://github.com/dotnet/coreclr/issues/5371#issuecomment-357793534

FYI this has regressed due to #15756

Comment in #15756 (comment) by @mikedn

Example diff that shows a range check no longer being eliminated: ...

It's unfortunate but it doesn't look like there are easy solutions to make the fix less conservative.

@benaadams
Copy link
Copy Markdown
Member

git clone issue

@dotnet-bot test Ubuntu x64 Checked Innerloop Build and Test (Jit - TieredCompilation=0)

@stephentoub stephentoub merged commit e41401e into dotnet:master Nov 27, 2018
@stephentoub stephentoub deleted the cqlocal branch November 27, 2018 14:27
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…net/coreclr#21192)

Enqueue/TryDequeue/TryPeek are all repeatedly accessing the same array from a readonly field.  Changing them to instead access that same array but from a cached local results in an ~10% throughput boost on a microbenchmark that does uncontended reads/writes of objects from/to the queue. (I also tried using a ref local to point directly to the target slot in the array, but that actually resulted in a measurable regression.)

Commit migrated from dotnet/coreclr@e41401e
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants