[vim/vim] eval: reduce string concat allocations (PR #19642)

0 views
Skip to first unread message

mattn

unread,
Mar 11, 2026, 8:43:08 PM (16 hours ago) Mar 11
to vim/vim, Subscribed

Reduce allocations in string .= and .. operations by using vim_realloc() to grow the existing buffer in place, avoiding an alloc/copy/free cycle on every concatenation.

Operation Before After Change
.= (append) 0.4877s 0.3957s -19%
.. (concat) 0.1511s 0.1490s (noise)

Note

The improvement is most visible with .= because the left-hand string grows repeatedly (e.g. let s .= 'x' in a loop). Without this patch, each iteration requires alloc/copy-all/free, making it O(n²) overall. vim_realloc() can often extend the buffer in place, avoiding the full copy. The .. benchmark concatenates two small fixed-size literals, so the copy cost is negligible regardless of the allocation strategy.


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

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

Commit Summary

  • a4aab3b eval: reduce string concat allocations

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/19642@github.com>

Reply all
Reply to author
Forward
0 new messages