Skip to content

Defer GetServiceInfo initialization in ActivatorUtilities#126005

Merged
MichalStrehovsky merged 4 commits intodotnet:mainfrom
MichalStrehovsky:digetsiinfo
Mar 25, 2026
Merged

Defer GetServiceInfo initialization in ActivatorUtilities#126005
MichalStrehovsky merged 4 commits intodotnet:mainfrom
MichalStrehovsky:digetsiinfo

Conversation

@MichalStrehovsky
Copy link
Member

Move the GetServiceInfo static field into a nested MethodInfoHolder class so the expensive Delegate.Method reflection call is deferred until the MethodInfo is actually needed, rather than at ActivatorUtilities class load time.

We don't need this field in native AOT builds at all, but it's difficult to eliminate automatically.

Move the GetServiceInfo static field into a nested MethodInfoHolder class
so the expensive Delegate.Method reflection call is deferred until the
MethodInfo is actually needed, rather than at ActivatorUtilities class
load time.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

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 optimizes ActivatorUtilities startup by deferring creation of a MethodInfo that previously required an eager Delegate.Method reflection call during type initialization.

Changes:

  • Moved the GetServiceInfo MethodInfo initialization into a nested holder type to lazy-initialize it on first use.
  • Updated the expression tree factory to reference the deferred MethodInfo via the new holder.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copilot AI review requested due to automatic review settings March 24, 2026 12:12
Copy link
Contributor

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

…tions/src/ActivatorUtilities.cs

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 24, 2026 14:18
Copy link
Contributor

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@MichalStrehovsky
Copy link
Member Author

/ba-g timeouts and #125933

@MichalStrehovsky MichalStrehovsky merged commit 9105b47 into dotnet:main Mar 25, 2026
81 of 88 checks passed
@MichalStrehovsky MichalStrehovsky deleted the digetsiinfo branch March 25, 2026 00:16
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.

6 participants