[vim/vim] Preallocate the output buffer in list2blob() (PR #21385)

4 views
Skip to first unread message

mattn

unread,
Sep 27, 2026, 8:25:51 PM (yesterday) Sep 27
to vim/vim, Subscribed

Reserve the output buffer in list2blob() using the known list length, then write validated bytes directly. This avoids repeated capacity checks and buffer growth. Add coverage for large conversions, descending ranges, and invalid trailing values.

Before/after timings for repeated conversions of a List containing repeating values 0–255 (median of five runs, GCC -O2; baseline 1b405bb705, patched cf21634360):

List elements Calls per run Before After Time reduction
4,096 4,882 103.284 ms 85.274 ms 17.4%
65,536 305 79.751 ms 64.278 ms 19.4%

Setup is excluded; replacing and freeing the previous result is included. These are focused microbenchmarks and were not CPU-pinned.

For one million valid elements, whole-process allocated memory after conversion decreased from 49.85 MB to 49.35 MB on Linux/glibc, measured with mallinfo2() (not RSS). Both versions retain Blob capacity after elements are removed.

The reservation happens before element validation, so invalid input can require unnecessary allocation and zeroing. For a million-element List with an invalid first value, 1,000 calls took 3.792 ms before and 17.546 ms after (five-run medians); both report E1239.


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

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

Commit Summary

  • cf21634 Preallocate the output buffer in list2blob()

File Changes

(2 files)

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/21385@github.com>

Christian Brabandt

unread,
3:14 PM (7 hours ago) 3:14 PM
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#21385)

thanks

—
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/21385/c5876744641@github.com>

Reply all
Reply to author
Forward
0 new messages