summaryrefslogtreecommitdiffstats
path: root/pkg/gui/types
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-06-22 13:34:15 +0200
committerStefan Haller <stefan@haller-berlin.de>2024-06-23 13:10:48 +0200
commit26132cf5bdae7ec81e9a0708c722ad2a9cf0c2cf (patch)
treeb27de3b227276cf54d39238e8162b79eb029567e /pkg/gui/types
parenta67eda39a56440f54be7fbb43974fa7a966bce53 (diff)
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
Diffstat (limited to 'pkg/gui/types')
0 files changed, 0 insertions, 0 deletions