[vim/vim] Speed up blob2list() with preallocated list items (PR #21386)

5 views
Skip to first unread message

mattn

unread,
Sep 27, 2026, 8:25:53 PM (3 days ago) Sep 27
to vim/vim, Subscribed

Use the known Blob length to allocate the result of blob2list() and all its list items together, avoiding one allocation per byte. Add coverage for removing, inserting, appending, reversing, and changing the type of result elements while preserving the original Blob.

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

Blob bytes Calls per run Before After Time reduction
4,096 488 35.639 ms 20.749 ms 41.8%
65,536 30 33.735 ms 20.311 ms 39.8%

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

Batch allocation reduces memory while the full result is retained, but its item storage remains allocated until the result list is freed. Removing a range also requires allocating separate list items for the removed values. With a one-million-byte Blob, whole-process allocated memory on Linux/glibc was:

State Before After
Full result retained, source Blob freed 48.35 MB 32.35 MB
Result filtered down to one element 0.35 MB 32.36 MB
remove(result, 1, 999999), both lists retained 48.35 MB 80.35 MB

These are mallinfo2() measurements, not RSS; MB means 1,000,000 bytes. The change also requires a contiguous allocation proportional to the Blob length.


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

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

Commit Summary

  • 23992b6 Speed up blob2list() with preallocated list items

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

Christian Brabandt

unread,
Sep 28, 2026, 2:53:51 PM (3 days ago) Sep 28
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#21386)

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

Reply all
Reply to author
Forward
0 new messages