Skip to content

Conversation

AaronRobinsonMSFT
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented Oct 3, 2025

Reverts #117792

This introduced a functional regression reported in #120347.

Reopened #117775 performance regression issue introduced in #113907.

Fixes #119986
Fixes #120347

@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 11.0.0 milestone Oct 3, 2025
@Copilot Copilot AI review requested due to automatic review settings October 3, 2025 17:58
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reverts a previous change that introduced ReaderWriterLockSlim in the RcwCache class, replacing it back with the standard Lock implementation due to a functional regression. The change restores the simpler locking mechanism to address reported issues with the ReaderWriterLockSlim implementation.

Key changes:

  • Reverts ReaderWriterLockSlim back to Lock with trivial waits optimization
  • Simplifies locking code by removing explicit try-finally blocks and using lock statements
  • Affects three methods: GetOrAddProxyForComInstance, FindProxyForComInstance, and Remove

@jkoritzinsky
Copy link
Member

Can we use an upgradable read lock (that upgrades to a write lock around the Remove call)? Or does that not fix the problem?

If we can avoid the perf regression from getting rid of the rwlock, I'd prefer that over taking the perf regression (for .NET 11 at least).

@AaronRobinsonMSFT
Copy link
Member Author

If we can avoid the perf regression from getting rid of the rwlock, I'd prefer that over taking the perf regression (for .NET 11 at least).

@jkoritzinsky Based on my comment at #117775 (comment), I don't think this fixed the regression either. At this point, I'm not sure we can address the regression in .NET 10 GA. We need to circle back and verify the actual regression though. The RPS system doesn't seem to be tracking the continued regression in this space.

@jkoritzinsky
Copy link
Member

I could have sworn this fixed the regression when I ran the benchmark locally and in my PR. Since it didn't, yeah let's revert and revisit.

@AaronRobinsonMSFT
Copy link
Member Author

/backport to release/10.0

Copy link
Contributor

github-actions bot commented Oct 3, 2025

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18230714561

@AaronRobinsonMSFT AaronRobinsonMSFT enabled auto-merge (squash) October 3, 2025 18:45
@AaronRobinsonMSFT AaronRobinsonMSFT merged commit caf8cf3 into main Oct 3, 2025
144 of 147 checks passed
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the revert-117792-comwrappers-rwlock branch October 3, 2025 20:11
{
_lock.EnterReadLock();
try
lock (_lock)
Copy link
Contributor

@rhuijben rhuijben Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here a readlock is not enough. It updates the hashtable under some circumstances, which may go concurrent under a read lock.

Copy link
Contributor

@rhuijben rhuijben Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrading to a write lock before the update (_cache.Remove()) may help too... But the single lock is probably just as easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComWrappers crash under stress With .NET 10 Preview 7, CanvasBitmap.LoadAsync of Win2D is broken.

3 participants