dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.25k stars 4.73k forks source link

IOptionsMonitor.Current always go though ConcurrentDictionary getter - perf? #109446

Open petrroll opened 23 hours ago

petrroll commented 23 hours ago

OptionsMonitor<T>.Current is not a field, it invokes a get on ConcurrentDictionary. In some codebases this can be used a lot. Sure, caching the current value is possible but the API surface doesn't make it obvious that it should be done.

I understand it's for simplicity allowing the same codepath to be used for named Config values as well as the default named string.Empty (which this property getter accesses) but it might be worth it to special case for the most common scenario and cache current value in a normal field so that access is essentially free (and inlinable and all that).

dotnet-policy-service[bot] commented 18 hours ago

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