Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve render performance #3686

Merged
merged 3 commits into from
Jun 23, 2024
Merged

Improve render performance #3686

merged 3 commits into from
Jun 23, 2024

Commits on Jun 23, 2024

  1. Don't redraw remote branches view when its width changes

    The rendering of remote branches is in no way dependent on the width of the view
    (or the screen mode). Unlike in the local branches view, we don't truncate long
    branch names here (because there's no more information after them).
    
    This is an error introduced in d5b4f7b.
    stefanhaller committed Jun 23, 2024
    Configuration menu
    Copy the full SHA
    8e1464f View commit details
    Browse the repository at this point in the history
  2. Rerender fewer views when their width changes

    In d5b4f7b and 58a83b0 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 58a83b0, but in a slightly
    different way.
    stefanhaller committed Jun 23, 2024
    Configuration menu
    Copy the full SHA
    a67eda3 View commit details
    Browse the repository at this point in the history
  3. Use utils.StringWidth to optimize rendering performance

    runewidth.StringWidth is an expensive call, even if the input string is pure
    ASCII. Improve this by providing a wrapper that short-circuits the call to len
    if the input is ASCII.
    
    Benchmark results show that for non-ASCII strings it makes no noticable
    difference, but for ASCII strings it provides a more than 200x speedup.
    
    BenchmarkStringWidthAsciiOriginal-10            718135       1637 ns/op
    BenchmarkStringWidthAsciiOptimized-10        159197538          7.545 ns/op
    BenchmarkStringWidthNonAsciiOriginal-10         486290       2391 ns/op
    BenchmarkStringWidthNonAsciiOptimized-10        502286       2383 ns/op
    stefanhaller committed Jun 23, 2024
    Configuration menu
    Copy the full SHA
    26132cf View commit details
    Browse the repository at this point in the history