[vim/vim] refactor: convert json_encode_item() from recursive to iterative (PR #19839)

2 views
Skip to first unread message

mattn

unread,
Mar 26, 2026, 8:32:30 PM (10 hours ago) Mar 26
to vim/vim, Subscribed

Convert json_encode_item() from a recursive implementation to an iterative one using an explicit stack (garray_T of json_enc_frame_T frames).

The recursive version uses C call stack proportional to nesting depth, which can cause a stack overflow (segfault) on deeply nested structures even when maxfuncdepth is set high enough to allow it. The iterative version uses heap-allocated frames, so nesting depth is limited only by available memory.

Benchmark comparison (average of 3 runs, ops/sec):

Test case master this branch change
string 456,603 459,764 +0.7%
number 446,534 453,610 +1.6%
small_dict 424,878 414,664 -2.4%
nested_list 341,987 337,716 -1.2%
deep_100 325,402 327,886 +0.8%
wide_1000 12,940 12,755 -1.4%
dict_100 79,998 83,109 +3.9%
mixed 68,109 74,406 +9.2%
blob 443,559 446,154 +0.6%

No performance regression. Complex structures (mixed, dict_100) show improvement.


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

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

Commit Summary

  • 792c107 refactor: convert json_encode_item() from recursive to iterative

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

Reply all
Reply to author
Forward
0 new messages