diff options
author | Lluis Sanchez <lluis@xamarin.com> | 2019-12-04 11:10:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-04 11:10:00 +0300 |
commit | 18c2c04bd15c8726c4d2deaef3ed8968e4de99bf (patch) | |
tree | f6f169f10877216974c59e36f96b6e7ae3880ad3 /main | |
parent | ce928d9dda263d87a05f0b11307761d32d7b3432 (diff) | |
parent | 996c6bd2d6e7edb3912d80204e2039651cf4dbfe (diff) |
Merge pull request #9414 from mono/backport-pr-9391-to-release-8.4
[release-8.4] [Ide] Load AddinManager data on the UI thread.
Diffstat (limited to 'main')
3 files changed, 33 insertions, 43 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/CompositionManager.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/CompositionManager.cs index ef092bf165..ade5b038d4 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/CompositionManager.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/CompositionManager.cs @@ -56,23 +56,12 @@ namespace MonoDevelop.Ide.Composition new AttributedPartDiscoveryV1 (StandardResolver), new AttributedPartDiscovery (StandardResolver, true)); - static Action HandleMefQueriedBeforeCompletion = UninitializedLogWarning; - - static void UninitializedLogWarning () - => LoggingService.LogWarning ("UI thread queried MEF while it was still being built:{0}{1}", Environment.NewLine, Environment.StackTrace); - - static void UninitializedThrowException () - => throw new InvalidOperationException ("MEF queried while it was still being built"); - - internal static void ConfigureUninitializedMefHandling (bool throwException) - => HandleMefQueriedBeforeCompletion = throwException ? new Action (UninitializedThrowException) : new Action (UninitializedLogWarning); - public static CompositionManager Instance {
get {
if (instance == null) {
var task = Runtime.GetService<CompositionManager> ();
- if (!task.IsCompleted && Runtime.IsMainThread) {
- HandleMefQueriedBeforeCompletion ();
+ if (!task.IsCompleted && Runtime.IsMainThread) { + LoggingService.LogWarning ("UI thread queried MEF while it was still being built:{0}{1}", Environment.NewLine, Environment.StackTrace); }
instance = task.WaitAndGetResult ();
}
@@ -83,7 +72,19 @@ namespace MonoDevelop.Ide.Composition protected override Task OnInitialize (ServiceProvider serviceProvider) { - return Task.Run (async () => await InitializeInstanceAsync ());
+ return Runtime.RunInMainThread (() => { + var timings = new Dictionary<string, long> (); + var metadata = new CompositionLoadMetadata (timings); + + var timer = Counters.CompositionLoad.BeginTiming (metadata); + var stepTimer = System.Diagnostics.Stopwatch.StartNew (); + + var mefAssemblies = ReadAssembliesFromAddins (timer); + + timings ["ReadFromAddins"] = stepTimer.ElapsedMilliseconds; + + return Task.Run (() => InitializeInstanceAsync (timer, mefAssemblies)); + }); } /// <summary> @@ -115,49 +116,42 @@ namespace MonoDevelop.Ide.Composition { } - async Task InitializeInstanceAsync () + async Task InitializeInstanceAsync (ITimeTracker<CompositionLoadMetadata> timer, HashSet<Assembly> mefAssemblies) {
- var timings = new Dictionary<string, long> ();
- var metadata = new CompositionLoadMetadata (timings);
-
- using (var timer = Counters.CompositionLoad.BeginTiming (metadata)) { - var fullTimer = System.Diagnostics.Stopwatch.StartNew ();
- var stepTimer = System.Diagnostics.Stopwatch.StartNew ();
-
- var mefAssemblies = ReadAssembliesFromAddins (timer);
- timings ["ReadFromAddins"] = stepTimer.ElapsedMilliseconds;
- stepTimer.Restart ();
- - var caching = new Caching (mefAssemblies, new IdeRuntimeCompositionExceptionHandler ()); + var metadata = timer.Metadata; + var fullTimer = System.Diagnostics.Stopwatch.StartNew (); + var stepTimer = System.Diagnostics.Stopwatch.StartNew (); - // Try to use cached MEF data + var caching = new Caching (mefAssemblies, new IdeRuntimeCompositionExceptionHandler ()); + // Try to use cached MEF data + using (timer) { var canUse = metadata.ValidCache = caching.CanUse (); - if (canUse) {
+ if (canUse) { LoggingService.LogInfo ("Creating MEF composition from cache"); RuntimeComposition = await TryCreateRuntimeCompositionFromCache (caching); - }
- timings ["LoadFromCache"] = stepTimer.ElapsedMilliseconds;
+ } + metadata.Timings ["LoadFromCache"] = stepTimer.ElapsedMilliseconds; stepTimer.Restart (); // Otherwise fallback to runtime discovery. - if (RuntimeComposition == null) {
+ if (RuntimeComposition == null) { LoggingService.LogInfo ("Creating MEF composition from runtime"); - var (runtimeComposition, catalog) = await CreateRuntimeCompositionFromDiscovery (caching, timer);
+ var (runtimeComposition, catalog) = await CreateRuntimeCompositionFromDiscovery (caching, timer); RuntimeComposition = runtimeComposition; CachedComposition cacheManager = new CachedComposition (); caching.Write (RuntimeComposition, catalog, cacheManager).Ignore (); - }
- timings ["LoadRuntimeComposition"] = stepTimer.ElapsedMilliseconds;
- stepTimer.Restart ();
+ } + metadata.Timings ["LoadRuntimeComposition"] = stepTimer.ElapsedMilliseconds; + stepTimer.Restart (); ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory (); ExportProvider = ExportProviderFactory.CreateExportProvider (); HostServices = Microsoft.VisualStudio.LanguageServices.VisualStudioMefHostServices.Create (ExportProvider); -
- timings ["CreateServices"] = stepTimer.ElapsedMilliseconds;
- metadata.Duration = fullTimer.ElapsedMilliseconds;
+ + metadata.Timings ["CreateServices"] = stepTimer.ElapsedMilliseconds; + metadata.Duration = fullTimer.ElapsedMilliseconds; }
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs index d70a5a2e76..48ef3614fb 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs @@ -315,8 +315,6 @@ namespace MonoDevelop.Ide Counters.InitializationTracker.Trace ("Running Startup Commands"); AddinManager.AddExtensionNodeHandler ("/MonoDevelop/Ide/StartupHandlers", OnExtensionChanged); - // Let extensions now access CompositionManager.Instance and start asynchronously composing the catalog - CompositionManager.ConfigureUninitializedMefHandling (throwException: false); Runtime.GetService<CompositionManager> ().Ignore (); } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs index 87558a25a0..afbbc4a0fe 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs @@ -88,8 +88,6 @@ namespace MonoDevelop.Ide { UnsetEnvironmentVariables (); - CompositionManager.ConfigureUninitializedMefHandling (throwException: true); - LoggingService.LogInfo ("Starting {0} {1}", BrandingService.ApplicationLongName, IdeVersionInfo.MonoDevelopVersion); LoggingService.LogInfo ("Build Information{0}{1}", Environment.NewLine, SystemInformation.GetBuildInformation ()); LoggingService.LogInfo ("Running on {0}", RuntimeVersionInfo.GetRuntimeInfo ()); |