[vim/vim] getbufline() is slower than necessary (PR #21223)

3 views
Skip to first unread message

Julien Voisin

unread,
Sep 4, 2026, 4:55:21 PM (yesterday) Sep 4
to vim/vim, Subscribed

Problem: get_buffer_lines() (getline()/getbufline()) allocates every
returned line's List item individually, even though the number
of lines is known in advance.
Solution: Allocate the List and all of its items in a single block with
list_alloc_with_items(), then fill each item in place.

This uses the same bulk-allocation idiom already present elsewhere in the codebase: list_concat() (list.c), tuple_copy()/tuple_slice() (tuple.c), and several list-construction sites in vim9execute.c.

Measured with "perf stat -e instructions" results byte-identical:

  • getline(1, '$') on a 5000-line buffer, repeated: -36.7%
  • getbufline() reading a 8000-line background buffer: -37.1%
  • getline(i, i + 39) 40-line windows over 20000 lines: -21.4%

The gain scales with the number of lines per call; whole-buffer reads (the common case for linters and formatters) save the most.


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

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

Commit Summary

  • ba3fc9c getbufline() 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/21223@github.com>

Reply all
Reply to author
Forward
0 new messages