[vim/vim] JSON control escapes use costly numeric formatting (PR #21381)

6 views
Skip to first unread message

mattn

unread,
Sep 27, 2026, 1:20:06 PM (3 days ago) Sep 27
to vim/vim, Subscribed

JSON encoding currently formats each ASCII control character without a short escape through vim_snprintf_safelen(). Generate the two hexadecimal digits of \u00xx directly, preserving the encoded output. Add coverage for all control escapes mixed with multibyte text across buffer growth, for both json_encode() and js_encode().

Before/after measurements for 1,000 calls to json_encode() on a 4,096-byte string (median of five runs, GCC -O2; baseline 1b405bb705, patched 0e6b0ddfb5):

Input Before After Time reduction
Control characters: repeat("\x01", 4096) 392.821 ms 27.634 ms 93.0%
Mixed text: repeat(repeat('a', 63) .. "\x1b", 64) 11.603 ms 6.563 ms 43.4%
Plain ASCII: repeat('a', 4096) 5.840 ms 5.819 ms 0.4% (essentially unchanged)

These are focused microbenchmarks; baseline and patched binaries were alternated between runs and were not CPU-pinned.

Validation: make -C src -j4 completed without compiler warnings, all eight tests in test_json.vim passed, and git diff --check passed.


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

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

Commit Summary

  • 0e6b0dd patch 9.2.NNNN: JSON control escapes use costly numeric formatting

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

Christian Brabandt

unread,
Sep 28, 2026, 3:46:33 PM (2 days ago) Sep 28
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#21381)

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

Reply all
Reply to author
Forward
0 new messages