Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Redundant DependencyContext instance #4335

Closed
DavidObando opened this issue Mar 23, 2016 · 10 comments
Closed

Redundant DependencyContext instance #4335

DavidObando opened this issue Mar 23, 2016 · 10 comments
Assignees
Milestone

Comments

@DavidObando
Copy link
Member

We're analyzing the memory state after running the HelloWorldMvc test and sending 1000 requests to it. Unexpectedly, we're seeing 2 instances of DependencyContext.

!dumpgen 2 -type Microsoft.Extensions.DependencyModel.DependencyContext
...
000002a49d43c858   00007FF9D2CD8410        72   Microsoft.Extensions.DependencyModel.DependencyContext
000002a49d70fb88   00007FF9D2AFAC88        72   Microsoft.Extensions.DependencyModel.DependencyContext

There are two instances of Microsoft.Extensions.DependencyModel.DependencyContext in gen2 memory, one for the DefaultAssemblyProvider, and another one for the DefaultRoslynCompilationService.

0:000> !mdt 000002a49d43c858
000002a49d43c858 (Microsoft.Extensions.DependencyModel.DependencyContext)
    <TargetFramework>k__BackingField:000002a49d322fb8 (System.String) Length=28, String=".NETStandardApp,Version=v1.5"
    <Runtime>k__BackingField:000002a49d0013f0 (System.String) 
    <IsPortable>k__BackingField:true (System.Boolean)
    <CompilationOptions>k__BackingField:000002a49d41ed48 (Microsoft.Extensions.DependencyModel.CompilationOptions)
    <CompileLibraries>k__BackingField:000002a49d43c8a0 (Microsoft.Extensions.DependencyModel.CompilationLibrary[], Elements: 149)
    <RuntimeLibraries>k__BackingField:000002a49d43cd60 (Microsoft.Extensions.DependencyModel.RuntimeLibrary[], Elements: 149)
    <RuntimeGraph>k__BackingField:000002a49d318460 (Microsoft.Extensions.DependencyModel.RuntimeFallbacks[], Elements: 0)
0:000> !gcroot 000002a49d43c858
Thread 1328:
    000000e363daee90 00007ff9d297a985 Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(Microsoft.AspNetCore.Hosting.IWebHost, System.Threading.CancellationToken, System.String) [C:\Users\daobando\AppData\Local\JetBrains\Shared\v04\DecompilerCache\decompiler\71F82A60-CE8D-4728-9B35-059123C0B904\e6\b1b02dd4\WebHostBuilderExtensions.cs @ 48]
        rbp-b8: 000000e363daeec8
            ->  000002a49d06ff48 Microsoft.AspNetCore.Hosting.Internal.WebHost
            ->  000002a49d08c9e0 Microsoft.Extensions.DependencyInjection.ServiceProvider
            ->  000002a49d08ca18 System.Collections.Generic.Dictionary`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.IService, Microsoft.Extensions.DependencyInjection],[System.Object, mscorlib]]
            ->  000002a49d286ce8 System.Collections.Generic.Dictionary`2+Entry[[Microsoft.Extensions.DependencyInjection.ServiceLookup.IService, Microsoft.Extensions.DependencyInjection],[System.Object, mscorlib]][]
            ->  000002a49d286ac0 Microsoft.Extensions.Options.OptionsManager`1[[Microsoft.AspNetCore.Mvc.MvcViewOptions, Microsoft.AspNetCore.Mvc.ViewFeatures]]
            ->  000002a49d286ad8 Microsoft.Extensions.Options.OptionsCache`1[[Microsoft.AspNetCore.Mvc.MvcViewOptions, Microsoft.AspNetCore.Mvc.ViewFeatures]]
            ->  000002a49d2875a8 Microsoft.AspNetCore.Mvc.MvcViewOptions
            ->  000002a49d287648 System.Collections.Generic.List`1[[Microsoft.AspNetCore.Mvc.ViewEngines.IViewEngine, Microsoft.AspNetCore.Mvc.ViewFeatures]]
            ->  000002a49d444350 Microsoft.AspNetCore.Mvc.ViewEngines.IViewEngine[]
            ->  000002a49d443f48 Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine
            ->  000002a49d43fea8 Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider
            ->  000002a49d43fed0 System.Func`2[[Microsoft.AspNetCore.Mvc.Razor.Compilation.RelativeFileInfo, Microsoft.AspNetCore.Mvc.Razor],[Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationResult, Microsoft.AspNetCore.Mvc.Razor]]
            ->  000002a49d43f890 Microsoft.AspNetCore.Mvc.Razor.Internal.RazorCompilationService
            ->  000002a49d318838 Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService
            ->  000002a49d43c858 Microsoft.Extensions.DependencyModel.DependencyContext

Found 1 unique roots (run '!GCRoot -all' to see all roots).
0:000> !mdt 000002a49d70fb88
000002a49d70fb88 (Microsoft.Extensions.DependencyModel.DependencyContext)
    <TargetFramework>k__BackingField:000002a49d5f62e8 (System.String) Length=28, String=".NETStandardApp,Version=v1.5"
    <Runtime>k__BackingField:000002a49d0013f0 (System.String) 
    <IsPortable>k__BackingField:true (System.Boolean)
    <CompilationOptions>k__BackingField:000002a49d6f2078 (Microsoft.Extensions.DependencyModel.CompilationOptions)
    <CompileLibraries>k__BackingField:000002a49d70fbd0 (Microsoft.Extensions.DependencyModel.CompilationLibrary[], Elements: 149)
    <RuntimeLibraries>k__BackingField:000002a49d710090 (Microsoft.Extensions.DependencyModel.RuntimeLibrary[], Elements: 149)
    <RuntimeGraph>k__BackingField:000002a49d065cf8 (Microsoft.Extensions.DependencyModel.RuntimeFallbacks[], Elements: 0)
0:000> !gcroot 000002a49d70fb88
Thread 1328:
    000000e363daee90 00007ff9d297a985 Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(Microsoft.AspNetCore.Hosting.IWebHost, System.Threading.CancellationToken, System.String) [C:\Users\daobando\AppData\Local\JetBrains\Shared\v04\DecompilerCache\decompiler\71F82A60-CE8D-4728-9B35-059123C0B904\e6\b1b02dd4\WebHostBuilderExtensions.cs @ 48]
        rbp-b8: 000000e363daeec8
            ->  000002a49d06ff48 Microsoft.AspNetCore.Hosting.Internal.WebHost
            ->  000002a49d08c9e0 Microsoft.Extensions.DependencyInjection.ServiceProvider
            ->  000002a49d08ca18 System.Collections.Generic.Dictionary`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.IService, Microsoft.Extensions.DependencyInjection],[System.Object, mscorlib]]
            ->  000002a49d286ce8 System.Collections.Generic.Dictionary`2+Entry[[Microsoft.Extensions.DependencyInjection.ServiceLookup.IService, Microsoft.Extensions.DependencyInjection],[System.Object, mscorlib]][]
            ->  000002a49d710740 Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentDescriptorCollectionProvider
            ->  000002a49d710728 Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentDescriptorProvider
            ->  000002a49d5f5678 Microsoft.AspNetCore.Mvc.Infrastructure.DefaultAssemblyProvider
            ->  000002a49d70fb88 Microsoft.Extensions.DependencyModel.DependencyContext

These objects seem to be identical, each consuming 1153536 (inclusive) bytes and containing the same data for all the fields that were inspected. The total usage of gen2 memory in this particular measurement was 7865208 bytes, meaning that each DependencyContext is ~1/6 of the consumed gen2 memory.

0:000> !objsize 000002a49d43c858
sizeof(000002a49d43c858) = 1153536 (0x119a00) bytes (Microsoft.Extensions.DependencyModel.DependencyContext)
0:000> !objsize 000002a49d70fb88
sizeof(000002a49d70fb88) = 1153536 (0x119a00) bytes (Microsoft.Extensions.DependencyModel.DependencyContext)
0:000> !dumpgen 2 -stat
...
77,309 objects, 7,817,480 bytes
Total GEN 2 size: 7,865,208 bytes

We should verify if this is intended.

/cc: @sajayantony @davidfowl @rynowak

@rynowak
Copy link
Member

rynowak commented Mar 23, 2016

This is a known issue tracked by https://github.com/dotnet/cli/issues/1736

@DavidObando
Copy link
Member Author

@rynowak dotnet/cli#1736 is about the references that the compilation options hold on to. This one is about there being 2 instances. It appears that we want to have just one, as both are identical.

@Eilon
Copy link
Member

Eilon commented Mar 24, 2016

If this is a very recent build, it might also be caused by some shenanigans due to us copying the dependency code into MVC itself to make it work with the most recent CLI. @pranavkm could that be the case?

@rynowak
Copy link
Member

rynowak commented Mar 24, 2016

Nah, this was the case before that change. This is going to be fixed by changes @javiercn is working on because IAssemblyProvider will go away.

We'll want to take a look at the Razor/Roslyn stuff across the board depending on what else @DavidObando finds. We might be holding on to too much.

@Eilon Eilon added this to the 1.0.0-rc2 milestone Mar 24, 2016
@Eilon
Copy link
Member

Eilon commented Mar 24, 2016

@javiercn parking this on your plate to verify after the parts feature is done.

@javiercn
Copy link
Member

javiercn commented Apr 1, 2016

Application parts are in and IAssemblyProvider is gone for good. @DavidObando what do we need to do here to verify?

@DavidObando
Copy link
Member Author

@javiercn cool!

Run the HelloWorldMvc process, load test it, and then attach WinDbg to it. Download sosex.dll from http://www.stevestechspot.com/, and load it.

.load C:\path\to\sosex.dll

Then execute:

!dumpgen 2 -type Microsoft.Extensions.DependencyModel.DependencyContext

You should see only one instance listed.

Let me know if you'd like me to test it too.

@rynowak
Copy link
Member

rynowak commented Apr 1, 2016

VS and dotmemory can also dump managed memory

@rynowak
Copy link
Member

rynowak commented Apr 4, 2016

image

@javiercn
Copy link
Member

javiercn commented Apr 4, 2016

@rynowak already took measurements this morning, so I'm closing this as fixed :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants