[release/11.0] Use acquire reads for cast cache entries - #133052
Open
github-actions[bot] wants to merge 1 commit into
Open
[release/11.0] Use acquire reads for cast cache entries#133052github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Replace the explicit read barrier in `CastCache.TryGet` with acquire reads of the source and target/result fields. The lookup uses a versioned entry: 1. acquire-read the version; 2. read the source and target/result payload; 3. re-read the version and reject the entry if it changed. The existing implementation uses ordinary loads followed by `Volatile.ReadBarrier()`. On ARM64 this emits `dmb ishld` in the hot cast-cache lookup path. Making the payload reads acquire operations preserves the required ordering of the final version check without the standalone barrier. #### ARM64 code generation The meothod body changes from ordinary loads plus `dmb ishld` to acquire loads. With RCpc available, the relevant sequence is now: ```asm ldapr w6, [x5] // version ldapur x7, [x5, #8] // source ... ldapur x7, [x5, #16] // target/result ... ldr w0, [x5] // final version check ``` There is no `dmb` in the generated method. On x64, volatile reads require no additional hardware instruction. #### Validation - `build.cmd -s clr -c Release -arch arm64` - Tested on a 32 core app running on new Arm64 hw (the `dmb ishld` was a bottleneck) Copilot-Session: 6bd43e03-841f-47ee-80f4-4da985b32a67
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Backport of #132630 to release/11.0
/cc @AndyAyersMS
Customer Impact
Internal customer was experiencing performance issues in this code on modern arm64 hardware on a highly concurrent server application.
Fix improves performance of their app by around 10%.
Regression
Testing
Verified by customer. Fix has been in main for about two weeks.
Risk
Low. No-op on xArch (with its stronger memory model).