Defer GetServiceInfo initialization in ActivatorUtilities#126005
Merged
MichalStrehovsky merged 4 commits intodotnet:mainfrom Mar 25, 2026
Merged
Defer GetServiceInfo initialization in ActivatorUtilities#126005MichalStrehovsky merged 4 commits intodotnet:mainfrom
MichalStrehovsky merged 4 commits intodotnet:mainfrom
Conversation
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>
Contributor
|
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection |
Contributor
There was a problem hiding this comment.
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
GetServiceInfoMethodInfoinitialization into a nested holder type to lazy-initialize it on first use. - Updated the expression tree factory to reference the deferred
MethodInfovia the new holder.
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Mar 24, 2026
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs
Outdated
Show resolved
Hide resolved
jkotas
approved these changes
Mar 24, 2026
rosebyte
approved these changes
Mar 24, 2026
mrek-msft
approved these changes
Mar 24, 2026
jkotas
reviewed
Mar 24, 2026
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com>
jkotas
reviewed
Mar 24, 2026
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs
Show resolved
Hide resolved
am11
reviewed
Mar 24, 2026
src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ActivatorUtilities.cs
Outdated
Show resolved
Hide resolved
…tions/src/ActivatorUtilities.cs Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Member
Author
|
/ba-g timeouts and #125933 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.