I have a relatively simple application, but the warm (second, etc.) startup time is terrible 3-5 seconds. The profiler (VS2010, processor fetch) shows that more than 80% of the time is spent on the Application.RunInternal (~ 40%) and XamlRader.LoadBaml (~ 40%) functions.
The root of the problem is that Window is created in a non-standard AppDomain. If I move on to creating a window in AppDomain by default or grant Unlimited AppDomain permission, everything will be as fast as expected.
I am testing:
- Windows Seven x64
- .Net 4.0
- 4Gb RAM
- GeForce 9800GT 1Gb.
I create an appdomain this way
var permissionSet = new PermissionSet(null); permissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution | SecurityPermissionFlag.SerializationFormatter | SecurityPermissionFlag.UnmanagedCode)); permissionSet.AddPermission(new ReflectionPermission(PermissionState.Unrestricted)); permissionSet.AddPermission(new UIPermission(PermissionState.Unrestricted)); permissionSet.AddPermission(new MediaPermission(PermissionState.Unrestricted)); permissionSet.AddPermission(new FileDialogPermission(PermissionState.Unrestricted)); var appDomainSetup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase, ApplicationName = AppDomain.CurrentDomain.SetupInformation.ApplicationName, DisallowApplicationBaseProbing = false, DisallowBindingRedirects = true, DisallowCodeDownload = true, DisallowPublisherPolicy = true, LoaderOptimization = LoaderOptimization.MultiDomainHost }; _appDomain = AppDomain.CreateDomain( name, null, appDomainSetup, permissionSet, new[] {
The behavior remains unchanged even if I delete XAML in an empty window
<Window x:Class="Rosmurta.Extensibility.WpfUI.RosmurtaWindow" x:ClassModifier="internal" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Test" Height="480" Width="640" WindowStyle="SingleBorderWindow"> <Grid> </Grid> </Window>
Not too much to understand with XamlRader.LoadBaml, but it spends more than 30% of the startup time for an empty window.
I tried (and it did not help)
- Adding <generatePublisherEvidence enabled = "false" /> to App.config.
- Adding the [LoaderOptimization (LoaderOptimization.MultiDomainHost)] attribute to the Main method.
- Adding signatures to all assemblies.
What else can be done?
source share