Skip to content

Commit e6eb67d

Browse files
committed
Minor performance improvements for InspectionResults View
Ignoring an inspection type no longer triggers a full reparse. Grouping behaviour changes are in a defer-cycle to avoid a rerender without any grouping.
1 parent e73eeec commit e6eb67d

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Rubberduck.Core/UI/Inspections/InspectionResultsViewModel.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,12 @@ public InspectionResultGrouping Grouping
230230
}
231231

232232
_grouping = value;
233-
// updating GroupDescriptions forces a Refresh
234-
Results.GroupDescriptions.Clear();
235-
Results.GroupDescriptions.Add(GroupDescriptions[_grouping]);
233+
// Deferring refresh to avoid a rerendering without grouping
234+
using (Results.DeferRefresh())
235+
{
236+
Results.GroupDescriptions.Clear();
237+
Results.GroupDescriptions.Add(GroupDescriptions[_grouping]);
238+
}
236239
OnPropertyChanged();
237240
}
238241
}
@@ -308,7 +311,6 @@ private void OpenSettings(object param)
308311
}
309312

310313
private bool _canQuickFix;
311-
312314
public bool CanQuickFix
313315
{
314316
get => _canQuickFix;
@@ -445,13 +447,12 @@ private async void RefreshInspections(CancellationToken token)
445447
}
446448

447449
stopwatch.Stop();
448-
LogManager.GetCurrentClassLogger().Trace("Inspection results rendered in {0}ms", stopwatch.ElapsedMilliseconds);
450+
Logger.Trace("Inspection results rendered in {0}ms", stopwatch.ElapsedMilliseconds);
449451
});
450452
}
451453

452-
private void InvalidateStaleInspectionResults(ICollection<QualifiedModuleName> modifiedModules)
454+
private void InvalidateUIStaleInspectionResults(ICollection<IInspectionResult> staleResults)
453455
{
454-
var staleResults = _results.Where(result => result.ChangesInvalidateResult(modifiedModules)).ToList();
455456
_uiDispatcher.Invoke(() =>
456457
{
457458
foreach (var staleResult in staleResults)
@@ -462,6 +463,13 @@ private void InvalidateStaleInspectionResults(ICollection<QualifiedModuleName> m
462463
});
463464
}
464465

466+
private void InvalidateStaleInspectionResults(ICollection<QualifiedModuleName> modifiedModules)
467+
{
468+
// materialize the collection to take work off of the UI thread
469+
var staleResults = _results.Where(result => result.ChangesInvalidateResult(modifiedModules)).ToList();
470+
InvalidateUIStaleInspectionResults(staleResults);
471+
}
472+
465473
private void ExecuteQuickFixCommand(object parameter)
466474
{
467475
var quickFix = parameter as IQuickFix;
@@ -554,14 +562,12 @@ private void ExecuteDisableInspectionCommand(object parameter)
554562

555563
Task.Run(() => _configService.Save(config));
556564

557-
_uiDispatcher.Invoke(() =>
558-
{
559-
RefreshCommand.Execute(null);
560-
});
565+
// remove inspection results of the selected inspection from the UI
566+
// collection is materialized to take work off of the UI thread
567+
InvalidateUIStaleInspectionResults(_results.Where(i => i.Inspection == _selectedInspection).ToList());
561568
}
562569

563570
private bool _canDisableInspection;
564-
565571
public bool CanDisableInspection
566572
{
567573
get => _canDisableInspection;

0 commit comments

Comments
 (0)