Skip to content

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Aug 31, 2025

No description provided.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 31, 2025
@jkotas
Copy link
Member Author

jkotas commented Aug 31, 2025

This should realize the small improvement from #119171 by changing the source code.

@jkotas jkotas changed the title Use more trim patterns for Type.DefaultBinder and CultureData Use more trim-friendly patterns for Type.DefaultBinder and CultureData Aug 31, 2025
@jkotas jkotas added area-NativeAOT-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Aug 31, 2025
@jkotas jkotas marked this pull request as ready for review August 31, 2025 15:24
@Copilot Copilot AI review requested due to automatic review settings August 31, 2025 15:24
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

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 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 using Interlocked.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

@jkotas
Copy link
Member Author

jkotas commented Aug 31, 2025

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.

jkotas and others added 2 commits August 31, 2025 08:30
…CultureData.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Nice!

@jkotas jkotas merged commit 99fb189 into dotnet:main Sep 2, 2025
144 checks passed
@jkotas jkotas deleted the trimming branch September 2, 2025 05:30
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.

2 participants