Umbraco-CMS: Umbraco starts very slowly due to TypeLoader / TypeFinder
Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)
13.2.0
Bug summary
The Umbraco startup time compared to a vanilla ASP.NET Core MVC app is unacceptably long – a fresh Umbraco 13.2.0 needs roughly 16 seconds to fully boot while a new MVC app is pretty much instant at 1-2 seconds.
I recently discovered that 90%+ of Umbraco’s startup time is spent by TypeLoader + TypeFinder which are used to find various types such as IComposer / IPropertyValueConverter / SurfaceController etc.
In my simple test, 15 out of the total 16 seconds is spent finding all the types in loaded assemblies which sounds completely insane:
It seems that it is faster when running repeated dotnet run commands. After a dotnet clean, however, it is always slow. Probably whenever any assembly has changed (so any new release of your website) it will be slow.
I suspect the complex logic in TypeFinder is iterating through all assemblies way more times than necessary but have not debugged this yet.
Note that 16 seconds is for an empty Umbraco installation. In a more serious website of ours it takes at least 25 seconds to find all types so unfortunately the delay gets only worse when more assemblies are being used in the site – which makes sense since there are more assemblies to scan through.
I have seen this behavior in Umbraco 10 websites we have, but TypeLoader seems to be part of Umbraco since at least v7 so I am afraid Umbraco boot times have been unnecessarily slow for 10+ years already.
Update
The slowdown is caused by ReferenceResolver.ResolveAssemblies which loads every single .dll file that is found in the bin folder, doing essentially this:
foreach (var dll in Directory.EnumerateFiles(dir ?? string.Empty, "*.dll"))
{
AssemblyName.GetAssemblyName(dll); // <- this takes 50-400ms PER DLL
}
I think it would make a lot of sense if the filters applied later would also be applied to the file name of the DLL, in that way bypassing the slow AssemblyName.GetAssemblyName(dll) call.
That is, if a file is called System.Linq.dll (for example), we should already skip it since System. is part of TypeFinder.KnownAssemblyExclusionFilter. Currently we only apply the those filters after the assembly has already been loaded which doesn’t really make sense.
So these filters apply to assemblyName at the moment but should also be applied to the filename. I will probably make a PR for that which should improve performance on startup a lot.
// don't include if this is excluded
if (TypeFinder.KnownAssemblyExclusionFilter.Any(f => assemblyName.FullName.StartsWith(f, StringComparison.InvariantCultureIgnoreCase)))
{
continue;
}
// don't include this item if it's Umbraco Core
if (Constants.Composing.UmbracoCoreAssemblyNames.Any(x => assemblyName.FullName.StartsWith(x) || (assemblyName.Name?.EndsWith(".Views") ?? false)))
{
continue;
}
Specifics
No response
Steps to reproduce
dotnet new install Umbraco.Templates::*- To ensure you run this on the latest version of Umbraco (13.2.0 at this moment)
dotnet new umbraco -n UmbracoBootcd UmbracoBoot- Open
appsettings.Development.json, changeSerilog:MinimumLevel:DefaulttoDebug:
{
"$schema": "appsettings-schema.json",
"Serilog": {
"MinimumLevel": {
"Default": "Debug" // <- Set to Debug instead of Information
}
}
dotnet run- Observe the first few lines of output in the log and see type loading takes insanely long.
- Look for the difference in times between these 2 lines:
[hh:mm:ss DBG] Getting Umbraco.Cms.Core.Dashboards.IDashboard: scanning assemblies.[hh:mm:ss DBG] Got Umbraco.Cms.Core.Dashboards.IDashboard, caching (true).- The time spent between these 2 lines makes up for 90%+ of the boot time.
- Look for the difference in times between these 2 lines:
Expected result / actual result
Umbraco should boot in a few seconds similar to a vanilla ASP.NET Core MVC app but instead takes at least 15-20 seconds which is getting worse and worse the more assemblies are added to the project.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 17 (16 by maintainers)
Yes, that’s exactly what it does, not just restart the site, it completely kills the process.