From 5c225cc43c05a5d6374aa2e3c2621a12c84dd549 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sun, 4 Jul 2021 22:32:11 +0800 Subject: [PATCH 1/3] Change bulk add condition --- Flow.Launcher/ViewModel/ResultsViewModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index 0766c7bbcd1..84e8a129c53 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -290,7 +290,7 @@ public void Update(List newItems, CancellationToken token = def if (Count == 0 && newItems.Count == 0 || _token.IsCancellationRequested) return; - if (editTime < 10 || newItems.Count < 30) + if (newItems.Count < 100) { if (Count != 0) RemoveAll(newItems.Count); AddAll(newItems); From 5dd19bf5200af03f7249ed1aac2a9d9303d70c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BC=98=E9=9F=AC?= Date: Mon, 12 Jul 2021 19:17:57 +0800 Subject: [PATCH 2/3] add warmup for bulkupdate --- Flow.Launcher/ViewModel/ResultsViewModel.cs | 31 +++++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index 84e8a129c53..da7630cdba3 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -8,6 +8,7 @@ using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; +using ABI.Windows.Services.Maps; namespace Flow.Launcher.ViewModel { @@ -26,6 +27,7 @@ public ResultsViewModel() Results = new ResultCollection(); BindingOperations.EnableCollectionSynchronization(Results, _collectionLock); } + public ResultsViewModel(Settings settings) : this() { _settings = settings; @@ -65,6 +67,7 @@ private int InsertIndexOf(int newScore, IList list) break; } } + return index; } @@ -83,7 +86,6 @@ private int NewIndex(int i) } } - #endregion #region Public Methods @@ -140,6 +142,7 @@ public void AddResults(List newRawResults, string resultId) UpdateResults(newResults); } + /// /// To avoid deadlock, this method should not called from main thread /// @@ -166,12 +169,12 @@ private void UpdateResults(List newResults, CancellationToken t switch (Visbility) { case Visibility.Collapsed when Results.Count > 0: - Margin = new Thickness { Top = 8 }; + Margin = new Thickness {Top = 8}; SelectedIndex = 0; Visbility = Visibility.Visible; break; case Visibility.Visible when Results.Count == 0: - Margin = new Thickness { Top = 0 }; + Margin = new Thickness {Top = 0}; Visbility = Visibility.Collapsed; break; } @@ -197,13 +200,15 @@ private List NewResults(IEnumerable resultsFo return Results; return Results.Where(r => r != null && !resultsForUpdates.Any(u => u.ID == r.Result.PluginID)) - .Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings))) - .OrderByDescending(rv => rv.Result.Score) - .ToList(); + .Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings))) + .OrderByDescending(rv => rv.Result.Score) + .ToList(); } + #endregion #region FormattedText Dependency Property + public static readonly DependencyProperty FormattedTextProperty = DependencyProperty.RegisterAttached( "FormattedText", typeof(Inline), @@ -217,7 +222,7 @@ public static void SetFormattedText(DependencyObject textBlock, IList value public static Inline GetFormattedText(DependencyObject textBlock) { - return (Inline)textBlock.GetValue(FormattedTextProperty); + return (Inline) textBlock.GetValue(FormattedTextProperty); } private static void FormattedTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -225,13 +230,14 @@ private static void FormattedTextPropertyChanged(DependencyObject d, DependencyP var textBlock = d as TextBlock; if (textBlock == null) return; - var inline = (Inline)e.NewValue; + var inline = (Inline) e.NewValue; textBlock.Inlines.Clear(); if (inline == null) return; textBlock.Inlines.Add(inline); } + #endregion public class ResultCollection : List, INotifyCollectionChanged @@ -260,6 +266,7 @@ public void BulkAddAll(List resultViews) // wpf use directx / double buffered already, so just reset all won't cause ui flickering OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } + private void AddAll(List Items) { for (int i = 0; i < Items.Count; i++) @@ -268,9 +275,11 @@ private void AddAll(List Items) if (_token.IsCancellationRequested) return; Add(item); - OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, i)); + OnCollectionChanged( + new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, i)); } } + public void RemoveAll(int Capacity = 512) { Clear(); @@ -299,12 +308,16 @@ public void Update(List newItems, CancellationToken token = def } else { + if (editTime < 5) + AddAll(newItems.GetRange(0, 100)); Clear(); + BulkAddAll(newItems); if (Capacity > 8000 && newItems.Count < 3000) { Capacity = newItems.Count; } + editTime++; } } From b46708038f1ebe91db5b9a919461511d9b1d7e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BC=98=E9=9F=AC?= Date: Sun, 8 Aug 2021 13:36:26 +0800 Subject: [PATCH 3/3] Remove condition check --- Flow.Launcher/ViewModel/ResultsViewModel.cs | 32 +++++++-------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/Flow.Launcher/ViewModel/ResultsViewModel.cs b/Flow.Launcher/ViewModel/ResultsViewModel.cs index da7630cdba3..42ccad63162 100644 --- a/Flow.Launcher/ViewModel/ResultsViewModel.cs +++ b/Flow.Launcher/ViewModel/ResultsViewModel.cs @@ -169,12 +169,12 @@ private void UpdateResults(List newResults, CancellationToken t switch (Visbility) { case Visibility.Collapsed when Results.Count > 0: - Margin = new Thickness {Top = 8}; + Margin = new Thickness { Top = 8 }; SelectedIndex = 0; Visbility = Visibility.Visible; break; case Visibility.Visible when Results.Count == 0: - Margin = new Thickness {Top = 0}; + Margin = new Thickness { Top = 0 }; Visbility = Visibility.Collapsed; break; } @@ -222,7 +222,7 @@ public static void SetFormattedText(DependencyObject textBlock, IList value public static Inline GetFormattedText(DependencyObject textBlock) { - return (Inline) textBlock.GetValue(FormattedTextProperty); + return (Inline)textBlock.GetValue(FormattedTextProperty); } private static void FormattedTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -230,7 +230,7 @@ private static void FormattedTextPropertyChanged(DependencyObject d, DependencyP var textBlock = d as TextBlock; if (textBlock == null) return; - var inline = (Inline) e.NewValue; + var inline = (Inline)e.NewValue; textBlock.Inlines.Clear(); if (inline == null) return; @@ -299,27 +299,15 @@ public void Update(List newItems, CancellationToken token = def if (Count == 0 && newItems.Count == 0 || _token.IsCancellationRequested) return; - if (newItems.Count < 100) + Clear(); + + BulkAddAll(newItems); + if (Capacity > 8000 && newItems.Count < 3000) { - if (Count != 0) RemoveAll(newItems.Count); - AddAll(newItems); - editTime++; - return; + Capacity = newItems.Count; } - else - { - if (editTime < 5) - AddAll(newItems.GetRange(0, 100)); - Clear(); - - BulkAddAll(newItems); - if (Capacity > 8000 && newItems.Count < 3000) - { - Capacity = newItems.Count; - } - editTime++; - } + editTime++; } } }