-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Improve perf of ActivatorUtilities.CreateInstance() by avoiding an alloc per ctor #99321
Conversation
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue DetailsThe current implementation allocs a struct for each ctor; the struct was changed to be Affects the CreateInstance* benchmarks; 3x-4x faster for existing benchmarks (which typically have 3 ctors);
|
How does changing the struct to ref struct avoids the allocation? |
Yes - sorry. This was premature and got conflated with a previous commit that cached the ConstructorInfoExs in a static. |
The current implementation allocs a struct for each ctor; the struct was changed to be
ref struct
\byref-like type
Found when working on #99175.
Affects the CreateInstance* benchmarks; 3x-4x faster for existing benchmarks (which typically have 3 ctors);