Open sebastienros opened 3 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
Tagging subscribers to this area: @eerhardt, @maryamariyan See info in area-owners.md if you want to be subscribed.
Author: | sebastienros |
---|---|
Assignees: | - |
Labels: | `area-Extensions-DependencyInjection`, `tenet-performance`, `untriaged` |
Milestone: | - |
The thing that stands out to me is the dictionary resize. We could potentially improve this by specifying a capacity like max(scoped/2, 30) something like this (I picked those numbers out of thin air)
@sebastienros - are there instructions on how to run this locally to investigate?
Here is how I do it:
src/OrchardCore.Cms.Web
run dotnet run -c release
/about
page (the simplest one)I can help more if you need. I can also provide this scenario as a crank
command.
I was discussing this with @maryamariyan and one thing we might want to try is re-using the scoped dictionary. This makes some assumption that scopes look the same and we have no idea to identify similar scopes (say by an id) so we can try it out with a small pool (say number of size of number of cores). This won't help for long running scopes in things like Blazor server, or Orleans but will do 2 things:
We might also want to keep the dictionaries to a reasonable size so we don't bloat memory (maybe calling TrimExcess if we reached some number of entries threshold).
Re-opening this as I reverted the change. I've added an event to the event source so we can figure out just how heterogeneous or homogenous scopes are within the same container.
Moving to 7.0 since this isn't a "must have" for 6.0.
In Orchard CMS which is quite allocaty, the second culprit is DI. This code path does a database request and renders the html. During that process several services are resolved, increasing the size of the scoped service dictionary.
Stack trace of allocations:
And overall memory consumption:
This issue is just to raise some concern, and maybe there is nothing better to be done.