diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-06-23 13:13:58 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-23 13:13:58 +0200 |
commit | cf40a5b077343cf6cf3de50b60fc4b47ce929dc1 (patch) | |
tree | b27de3b227276cf54d39238e8162b79eb029567e /pkg/utils/formatting_test.go | |
parent | a62a5089d6ed5ba989279590a5bd3426829c856d (diff) | |
parent | 26132cf5bdae7ec81e9a0708c722ad2a9cf0c2cf (diff) |
Improve render performance (#3686)
- **PR Description**
Fix a performance regression that I introduced with v0.41: when entering
or leaving staging mode for a file, or when switching from a file that
has only unstaged changes to one that has both staged and unstaged
changes, there was a noticeable lag of about 500ms on my machine. With
the improvements in this PR we get this back down to about 20ms.
Diffstat (limited to 'pkg/utils/formatting_test.go')
-rw-r--r-- | pkg/utils/formatting_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/utils/formatting_test.go b/pkg/utils/formatting_test.go index 5b56a9b33..ac2adee5f 100644 --- a/pkg/utils/formatting_test.go +++ b/pkg/utils/formatting_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "github.com/mattn/go-runewidth" "github.com/stretchr/testify/assert" ) @@ -250,3 +251,27 @@ func TestRenderDisplayStrings(t *testing.T) { assert.EqualValues(t, test.expectedColumnPositions, columnPositions) } } + +func BenchmarkStringWidthAsciiOriginal(b *testing.B) { + for i := 0; i < b.N; i++ { + runewidth.StringWidth("some ASCII string") + } +} + +func BenchmarkStringWidthAsciiOptimized(b *testing.B) { + for i := 0; i < b.N; i++ { + StringWidth("some ASCII string") + } +} + +func BenchmarkStringWidthNonAsciiOriginal(b *testing.B) { + for i := 0; i < b.N; i++ { + runewidth.StringWidth("some non-ASCII string 🍉") + } +} + +func BenchmarkStringWidthNonAsciiOptimized(b *testing.B) { + for i := 0; i < b.N; i++ { + StringWidth("some non-ASCII string 🍉") + } +} |