Skip to content

DI allocations improvements #47607

Description

@sebastienros

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:

Name                                                                                                                                                                                                                                  	Inc %
 Type Entry[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCacheKey,System.Object][]                                                                                                                                   	  7.8
+ coreclr!?                                                                                                                                                                                                                           	  7.8
|+ System.Private.CoreLib.il!System.Collections.Generic.Dictionary`2[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCacheKey,System.__Canon].Resize(int32,bool)                                                        	  7.8
||+ System.Private.CoreLib.il!System.Collections.Generic.Dictionary`2[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCacheKey,System.__Canon].TryInsert(!0,!1,value class System.Collections.Generic.InsertionBehavior)	  7.8
|| + System.Private.CoreLib.il!System.Collections.Generic.Dictionary`2[Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCacheKey,System.__Canon].Add(!0,!1)                                                              	  7.8
||  + microsoft.extensions.dependencyinjection.il!dynamicClass.ResolveService(pMT: 00007FF84C1DFF08,pMT: 00007FF84C1D9B20)                                                                                                            	  7.8
||   + microsoft.extensions.dependencyinjection.il!dynamicClass.ResolveService(pMT: 00007FF84C1DFF08,pMT: 00007FF84C1D9B20)                                                                                                           	  7.8
||    + microsoft.extensions.dependencyinjection.abstractions.il!ServiceProviderServiceExtensions.GetRequiredService                                                                                                                  	  4.8
||    |+ microsoft.extensions.dependencyinjection.abstractions.il!ServiceProviderServiceExtensions.GetRequiredService                                                                                                                 	  4.8
||    | + orchardcore.displaymanagement.liquid!OrchardCore.DisplayManagement.Liquid.LiquidTemplateContextExtensions+<EnterScopeAsync>d__0.MoveNext()                                                                                  	  4.5

And overall memory consumption:

Name                                                                                                                                         Exc %  ExcInc %     Inc Fold                            When
?!?                                                                                                                                           8.66,57215.5  11,8571,7788389CDDoDCDFED9ECFFFDGGHFFE89DY*
e_sqlite3!?                                                                                                                                   4.03,088 6.1   4,7011,36762526767655664565557556565569535
microsoft.extensions.dependencyinjection.il!dynamicClass.ResolveService(pMT: 00007FF84C1DFF08,pMT: 00007FF84C1D9B20)                          2.92,217 5.4   4,1341,907105o556655665546566567566564630o
orchardcore.displaymanagement!OrchardCore.DisplayManagement.Implementation.DefaultHtmlDisplay+<ExecuteAsync>d__7.MoveNext()                   2.72,09728.1  21,4691,95400N5WWXVWVVVWSOXUWWXXVWXWWXRWN9.
orchardcore.contentmanagement.display!OrchardCore.ContentManagement.Display.ContentItemDisplayCoordinator+<BuildDisplayAsync>d__9.MoveNext() 2.31,74910.0   7,6481,6760_81BCABBBABB99CBBACBABBBCCBD92_
System.Private.CoreLib.il!AsyncMethodBuilderCore.Start                                                                                        2.21,69071.9  54,9611,42801****************************3_
orchardcore.displaymanagement!OrchardCore.DisplayManagement.Views.ShapeResult+<ApplyImplementationAsync>d__17.MoveNext()                      2.01,540 5.2   4,0081,4130o40665656555446655655656666741_
orchardcore.displaymanagement.liquid!OrchardCore.DisplayManagement.Liquid.Tags.HelperStatement+<WriteToAsync>d__4.MoveNext()                  1.91,47413.0   9,9651,38200A3FGFFEEEEEDBGEEEFEEEFFGGCDA51
ntoskrnl!RtlpLookupFunctionEntryForStackWalks                                                                                                 1.91,437 1.9   1,437  242__o012222223221122222o222220____
orchardcore.displaymanagement.liquid!LiquidTagHelperActivator.Create                                                                          1.91,428 2.3   1,7831,3710o202222222222132232222233222110

This issue is just to raise some concern, and maybe there is nothing better to be done.

Metadata

Metadata

Assignees

Labels

area-Extensions-DependencyInjectionin-prThere is an active PR which will close this issue when it is mergedneeds-author-actionAn issue or pull request that requires more info or actions from the author.tenet-performancePerformance related issue

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions