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.
https://github.com/vim/vim/pull/19839
(1 file)
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()