Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Merge changes from TFS - #1335

Merged
MichalStrehovsky merged 1 commit into
dotnet:nmirrorfrom
dotnet-bot:from-tfs
May 28, 2016
Merged

MichalStrehovsky merged 1 commit into
dotnet:nmirrorfrom
dotnet-bot:from-tfs

Conversation

@dotnet-bot

Copy link
Copy Markdown
Collaborator

No description provided.

CR: JKotas, DavidWr

The generic ConditionalWeakTable class uses the non-generic DependentHandle struct to store GC handles for keys and values.  Runtime type casts from objects back to TKey and TValue types are relatively expensive as they involve extracting the corresponding EETypePtr from the generic dictionary and calling the runtime casting routine.  The main change here is skipping certainly safe type casts in ConditionalWeakTable code by using RuntimeHelpers.UncheckedCast intrinsic.  One alternative approach would be making the DependentHandle struct generic; however, that would emit extra EETypes into SharedLibrary.dll.

Details:
*  Move LockHolder.cs file from TypeLoader to Common and add it to System.Private.CoreLib assembly.
*  Monitor.cs:  Move ConditionalWeakTable and delegate initialization to the class constructor so that we do not need to check whether they have been initialized on each GetLock or GetCondition call.
*  ClassConstructorRunner.cs:
    -  Use the LockHolder pattern to avoid potential reentrancy issues with Monitor..cctor after the change in Monitor.cs.
    -  Use raw EETypePtr equality when checking for the Lock type in the GetLock method to improve its performance.  This check is temporary and will be removed after we fix Framework code to directly use Lock.Acquire/Release methods instead of the lock statement on Lock objects.
*  ConditionalWeakTable.cs:  Use the LockHolder pattern for update operations.  Replace certainly safe type casts with RuntimeHelpers.UncheckedCast intrinsic calls.

With these changes I am observing ~28% throughput improvement for locking on normal types, and ~21% throughput improvement for locking on the special System.Threading.Lock type for x86ret build with SharedLibrary.dll.  These numbers should be taken with a grain of salt as they depend on inlining decisions and binary code layout.

[tfs-changeset: 1608989]
@MichalStrehovsky
MichalStrehovsky merged commit 5e28781 into dotnet:nmirror May 28, 2016
@dotnet-bot
dotnet-bot deleted the from-tfs branch May 28, 2016 01:20
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.

4 participants