-
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
Reduce allocations in Microsoft.Extensions.Configuration #88211
Conversation
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsCurrently calculating paths always allocates a
|
src/libraries/Microsoft.Extensions.Configuration.Binder/src/ConfigurationBinder.cs
Show resolved
Hide resolved
@pentp did you run into any allocation problem to provide such fixes? or you just proactively looking for places we can optimize? Is it possible to provide some allocation numbers to see if it is worth optimizing? We are trying to be careful touch the configuration binding code as we experienced some regressions before. |
I just noticed that the configuration key (path) generation code was really wasteful when I was adopting a new configuration loading mechanisms for our app, but didn't gather any numbers. |
src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/ConfigurationPath.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/ConfigurationPath.cs
Outdated
Show resolved
Hide resolved
@@ -69,11 +69,11 @@ public ConfigurationSection(IConfigurationRoot root, string path) | |||
{ | |||
get | |||
{ | |||
return _root[ConfigurationPath.Combine(Path, key)]; | |||
return _root[Path + ConfigurationPath.KeyDelimiter + key]; |
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.
Here are three places where the lookup-key is created. Although it's trivial code, should this be moved to a helper method in order to have only one place where that lookup-key is built?
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.
Ideally, should add an overload to ConfigurationPath.Combine
that takes two path strings (the most common case), but adding it as an internal API wouldn't work because it's in a different assembly and adding a public API needs the full API review process. I'm willing to create an API review request for this, if it sounds useful enough?
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.
I don't think a public API is needed here. I thought just a helper in ConfigurationSection
(as the PR's diff shows three places where that could be used).
…src/ConfigurationPath.cs Co-authored-by: Günther Foidl <[email protected]>
…src/ConfigurationPath.cs Co-authored-by: Günther Foidl <[email protected]>
Currently calculating paths always allocates a
string[]
just to concatenate 3 strings.