[vim/vim] computing the displayed width of a line is slower than necessary (PR #21210)

4 views
Skip to first unread message

Julien Voisin

unread,
Sep 2, 2026, 4:00:30 PM (4 days ago) Sep 2
to vim/vim, Subscribed

Problem: Computing the displayed width of a line calls win_lbr_chartabsize()
for every character, even when the simpler win_nolbr_chartabsize()
would return the same result.
Solution: In win_linetabsize_cts() determine once whether the line needs the
full calculation and otherwise call win_nolbr_chartabsize() directly.

win_linetabsize_cts() computes the displayed width of a line, which happens very often, for example in plines() while scrolling and positioning the cursor. For every character it called win_lbr_chartabsize(). In the common case where 'wrap' is set and none of 'linebreak', 'breakindent', 'showbreak' or text properties that insert text are active, that function does nothing more than return win_nolbr_chartabsize(). Testing these conditions once per line instead of once per character and then calling win_nolbr_chartabsize() directly avoids the extra work with no change in the computed width.

Benchmarked with retired instructions, running a scripted navigation session (page up/down, jump to top/bottom, line stepping and searches) over real files:

file (settings)                          before      after     change
log file, ~250-col lines, 'wrap'         4.857e9    4.026e9    -17.1%
C source, syntax on, 'wrap'              9.765e9    9.596e9     -1.7%
help file, syntax on, 'wrap'            21.509e9   21.191e9     -1.5%
C source, syntax on, 'nowrap'            9.254e9    9.255e9      none

The gain is largest for wrapped long lines with little or no syntax highlighting, smaller when syntax highlighting dominates, and none with 'nowrap' since the fast path applies only when 'wrap' is set.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/21210

Commit Summary

  • bcfe87e computing the displayed width of a line is slower than necessary

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/21210@github.com>

Reply all
Reply to author
Forward
0 new messages