-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Use more trim-friendly patterns for Type.DefaultBinder and CultureData #119226
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
Conversation
This should realize the small improvement from #119171 by changing the source code. |
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs
Show resolved
Hide resolved
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
There was a problem hiding this 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 modernizes type initialization patterns and improves thread safety in reflection-related code. The changes focus on using more trim-friendly patterns for Type.DefaultBinder
and CultureData
, replacing outdated collection initialization syntax with modern C# collection expressions.
- Replaces
Type.EmptyTypes
references with modern collection expression syntax[]
- Modernizes
Type.DefaultBinder
implementation to use singleton pattern instead of lazy initialization with locks - Improves thread safety in
CultureData
caching by usingInterlocked.CompareExchange
pattern
Reviewed Changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/libraries/System.Private.CoreLib/src/System/Type.cs | Updates DefaultBinder to use singleton pattern and replaces EmptyTypes with [] |
src/libraries/System.Private.CoreLib/src/System/DefaultBinder.cs | Implements singleton Instance property and updates Missing.Value references |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs | Improves thread safety using Interlocked.CompareExchange pattern |
Multiple reflection files | Replace Type.EmptyTypes with modern collection expression [] |
src/coreclr files | Updates native AOT and CoreCLR implementations to use modern patterns |
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs
Show resolved
Hide resolved
The main improvement is realized by avoiding dependencies on System.Type public static fields. System.Type exposes static fields in the public surface and so referencing one of the fields will bring all of them into the dependency graph via the static constructor. |
…CultureData.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
No description provided.