From 9bd8f08e9714700fd08594d9cbeb490702895450 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 14 May 2025 06:42:00 -0500 Subject: [PATCH] CmdPal: fix a perf regression loading pages This was especially noticable with the icons extension. Turns out in #39051, when I was experimenting with getting AoT clean, i accidentally called this twice. Then we actually commited that straight up. This PR reverts that. It also moves a similar case where we were initializing all the tags on the UI thread. That's wrong too - we need to fetch properties off the UI thread, then update the list on the UI thread. Closes nothing, I didn't file this yet. --- .../ListItemViewModel.cs | 16 ++++++++-------- .../ShellViewModel.cs | 5 +---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListItemViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListItemViewModel.cs index ab7990e7819d..48542ba628f0 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListItemViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ListItemViewModel.cs @@ -107,17 +107,17 @@ protected override void FetchProperty(string propertyName) private void UpdateTags(ITag[]? newTagsFromModel) { + var newTags = newTagsFromModel?.Select(t => + { + var vm = new TagViewModel(t, PageContext); + vm.InitializeProperties(); + return vm; + }) + .ToList() ?? []; + DoOnUiThread( () => { - var newTags = newTagsFromModel?.Select(t => - { - var vm = new TagViewModel(t, PageContext); - vm.InitializeProperties(); - return vm; - }) - .ToList() ?? []; - // Tags being an ObservableCollection instead of a List lead to // many COM exception issues. Tags = new(newTags); diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs index d86831d0a116..d9212733eb80 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/ShellViewModel.cs @@ -4,7 +4,6 @@ using System.Runtime.InteropServices; using System.Runtime.Versioning; -using CommunityToolkit.Common; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Messaging; @@ -109,13 +108,11 @@ public void LoadPageViewModel(PageViewModel viewModel) // TODO GH #239 switch back when using the new MD text block // _ = _queue.EnqueueAsync(() => _ = Task.Factory.StartNew( - async () => + () => { // bool f = await viewModel.InitializeCommand.ExecutionTask.; // var result = viewModel.InitializeCommand.ExecutionTask.GetResultOrDefault()!; // var result = viewModel.InitializeCommand.ExecutionTask.GetResultOrDefault()!; - var result = await viewModel.InitializeAsync(); - CurrentPage = viewModel; // result ? viewModel : null; ////LoadedState = result ? ViewModelLoadedState.Loaded : ViewModelLoadedState.Error; },