-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Optimize capturing lambdas in DependencyContextExtensions
and DependencyContextJsonReader
#92462
Conversation
Tagging subscribers to this area: @dotnet/area-dependencymodel Issue Detailsclose #87911
|
`DependencyContextExtensions` and `DependencyContextJsonReader` originally use lambdas capturing local variables, resulting in unnecessary allocations. The PR replaces them with helper functions with static lambdas. Fix dotnet#87911
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.
It looks to me like the issue this issue attempts to address has an open question about the scenario being measured that notices/cares about the performance here. @Youssef1313 can you chime in on that? @ViktorHofer -- looks like you marked the original issue help-wanted
can you have a look at this?
src/libraries/System.Linq/src/System/Linq/SelectManyWithParameterHelpers.cs
Outdated
Show resolved
Hide resolved
@ericstj I don't have much info other than seeing these allocations at the startup of an Uno Platform Skia application. From the trace screenshots posted in the issue, it seems like all Uno does is this: Then Silk.NET calls into this code and then we see these allocations. |
src/libraries/System.Linq/src/System/Linq/SelectManyWithParameterHelpers.cs
Outdated
Show resolved
Hide resolved
I'm also surprised that this code is executed on the hot path. Nevertheless, the optimization looks trivial (replacing the lamda with a loop) so I'm OK with that. As the extension helper file is only used in a single place, it makes sense to put it next to where it is used (in DependencyModel). |
Here's the place in Silk.NET that's using this: https://github.com/dotnet/Silk.NET/blob/d4d55347bb5d4aa9f316b516abf05ed4d8a66bfe/src/Core/Silk.NET.Core/Loader/DefaultPathResolver.cs#L212 Probably better to use https://learn.microsoft.com/en-us/dotnet/api/system.runtime.loader.assemblydependencyresolver.resolveunmanageddlltopath?view=net-7.0 |
close #87911
I am kind of uncertain where to put the helper methods, as I don't want to pollute other namespaces but the methods' function are very generic and might be useful to others.