]> git.ipfire.org Git - thirdparty/vim.git/commit
patch 9.2.0431: blob encoding can be improved v9.2.0431
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Sat, 2 May 2026 15:39:55 +0000 (15:39 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 2 May 2026 15:39:55 +0000 (15:39 +0000)
commite1e92fea92ed80dd10ff0cb325433a97c1826b6a
tree18ad92785892611a14c2bdf769c88bbbec8d1bff
parent2219c890136f4c809ca4fa64d357ae46442bfa92
patch 9.2.0431: blob encoding can be improved

Problem:  blob encoding can be improved
Solution: Speed up blob encoding by avoiding per-byte ga_append()
          (Yasuhiro Matsumoto)

Replace the per-byte ga_append loop in the VAR_BLOB branch of
json_encode_item() with a single ga_grow for the worst case
(2 + 4 * blen) and direct writes through a local pointer. Also
read blob bytes through a local char_u* instead of going through
blob_get() for each byte.

Benchmark (1 MiB blob, 5 iterations, total seconds, median of 3 runs):

| byte distribution | Before | After | Speedup |
|---|---:|---:|---:|
| 1-digit (0–9)     | 0.0254 | 0.0174 | 1.46x |
| 2-digit (10–99)   | 0.0344 | 0.0064 | 5.38x |
| 3-digit (100–255) | 0.0539 | 0.0102 | 5.28x |
| mixed (0–255)     | 0.0335 | 0.0093 | 3.60x |

closes: #20113

Signed-off-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/json.c
src/version.c