From a67eda39a56440f54be7fbb43974fa7a966bce53 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 22 Jun 2024 18:00:31 +0200 Subject: Rerender fewer views when their width changes In d5b4f7bb3e and 58a83b0862 we introduced a combined mechanism for rerendering views when either their width changes (needed for the branches view which truncates long branch names), or the screen mode (needed for those views that display more information in half or full screen mode, e.g. the commits view). This was a bad idea, because it unnecessarily rerenders too many views when just their width changes, which causes a noticable lag. This is a problem, for example, when selecting a file in the files panel that has only unstaged changes, and then going to one that has both staged and unstaged changes; this splits the main view, causing the side panels to become a bit narrower, and rerendering all those views took almost 500ms on my machine. Another similar example is entering or leaving staging mode. Fix this by being more specific about which views need rerendering under what conditions; this improves the time it takes to rerender in the above scenarios from 450-500s down to about 20ms. This reintroduces the code that was removed in 58a83b0862, but in a slightly different way. --- pkg/gui/types/context.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'pkg/gui/types') diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index 003035fc2..70458c16f 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -39,6 +39,18 @@ type ParentContexter interface { GetParentContext() (Context, bool) } +type NeedsRerenderOnWidthChangeLevel int + +const ( + // view doesn't render differently when its width changes + NEEDS_RERENDER_ON_WIDTH_CHANGE_NONE NeedsRerenderOnWidthChangeLevel = iota + // view renders differently when its width changes. An example is a view + // that truncates long lines to the view width, e.g. the branches view + NEEDS_RERENDER_ON_WIDTH_CHANGE_WHEN_WIDTH_CHANGES + // view renders differently only when the screen mode changes + NEEDS_RERENDER_ON_WIDTH_CHANGE_WHEN_SCREEN_MODE_CHANGES +) + type IBaseContext interface { HasKeybindings ParentContexter @@ -60,8 +72,8 @@ type IBaseContext interface { // determined independently. HasControlledBounds() bool - // true if the view needs to be rerendered when its width changes - NeedsRerenderOnWidthChange() bool + // to what extent the view needs to be rerendered when its width changes + NeedsRerenderOnWidthChange() NeedsRerenderOnWidthChangeLevel // true if the view needs to be rerendered when its height changes NeedsRerenderOnHeightChange() bool -- cgit v1.2.3