Skip to content

Commit

Permalink
perf(RevisionDataGridView): Remove special OnScroll handler
Browse files Browse the repository at this point in the history
Refs: #11719
  • Loading branch information
mstv committed May 12, 2024
1 parent cda3611 commit a340186
Showing 1 changed file with 1 addition and 32 deletions.
33 changes: 1 addition & 32 deletions GitUI/UserControls/RevisionGrid/RevisionDataGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ public sealed partial class RevisionDataGridView : DataGridView

private readonly BackgroundUpdater _rowCountUpdater;
private readonly BackgroundUpdater _visibleRowRangeUpdater;
private readonly Stopwatch _lastRepaint = Stopwatch.StartNew();
private readonly Stopwatch _lastScroll = Stopwatch.StartNew();
private readonly Stopwatch _consecutiveScroll = Stopwatch.StartNew();
private readonly List<ColumnProvider> _columnProviders = [];
private readonly TaskManager _taskManager = ThreadHelper.CreateTaskManager();
private readonly CancellationTokenSequence _updateVisibleRowRangeSequence = new();
Expand Down Expand Up @@ -113,11 +110,10 @@ public RevisionDataGridView()
}
};

Scroll += (_, _) => OnScroll();
Scroll += (_, _) => UpdateVisibleRowRange();
Resize += (_, _) => UpdateVisibleRowRange();
GotFocus += (_, _) => InvalidateSelectedRows();
LostFocus += (_, _) => InvalidateSelectedRows();
RowPrePaint += (_, _) => _lastRepaint.Restart();

CellPainting += OnCellPainting;
CellFormatting += (_, e) =>
Expand Down Expand Up @@ -290,8 +286,6 @@ private Brush GetBackground(bool isSelected, bool isFocused, int rowIndex, GitRe

private void OnCellPainting(object? sender, DataGridViewCellPaintingEventArgs e)
{
_lastRepaint.Restart();

DebugHelpers.Assert(_rowHeight != 0, "_rowHeight != 0");

if (e.RowIndex < 0 ||
Expand Down Expand Up @@ -661,31 +655,6 @@ private void SetRowCountAndSelectRowsIfReady()
}
}

private void OnScroll()
{
UpdateVisibleRowRange();

// When scrolling many rows within a short time, the message pump is
// flooded with WM_CTLCOLORSCROLLBAR messages and the DataGridView
// is not repainted. This happens for example when the mouse wheel
// is spinning fast (with free-spinning mouse wheels) or while dragging
// the scroll bar fast. In such cases, force a repaint to make the GUI
// feel more responsive.
if (_lastScroll.ElapsedMilliseconds > 100)
{
_consecutiveScroll.Restart();
}

if (_consecutiveScroll.ElapsedMilliseconds > 50
&& _lastRepaint.ElapsedMilliseconds > 50)
{
Update();
_lastRepaint.Restart();
}

_lastScroll.Restart();
}

private void TriggerRowCountUpdate()
{
_rowCountUpdater.ScheduleExecution();
Expand Down

0 comments on commit a340186

Please sign in to comment.