Repository navigation
fix: render Thrift complex values in linear time - #597
vuanhphung wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good, with 1 low concern. I traced the recursive append path against the old concatenation code. Null handling, slice offsets, map key quoting, complex map keys and error propagation all match, and the golden tests cover each of these.
b5f00a4 to
3c548d6
Compare
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Nit
Looks good: no blocking issues. The rewrite to a single append buffer gives the same output as the old code, including null handling, offsets, and escaped keys and field names. The complex flag is only set on list, map and struct containers, so the complexValueAppender assertion can't panic.
Other findings
- ⚪ Nit — The parameter
complexinappendColumnValueshadows Go's built-incomplex. It compiles and behaves correctly, but it is a style nit. Rename it tonestedorisComplex. (Found by Claude Opus 5.5 · confirmed by the judge)
|
Re the naming nit: This comment was generated with GitHub MCP. |
3c548d6 to
485590d
Compare
485590d to
0b64f1b
Compare
0b64f1b to
3e3ae23
Compare
3e3ae23 to
f77ef01
Compare
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good overall, with 1 low concern. The append-based rendering produces the same output as before, nested containers never touch their own buffers, and the buffers are cleared on SetValueArray and Release. The tests and the e2e query exercise the native complex path, which is on by default.
f77ef01 to
02573a1
Compare
02573a1 to
ac22c3e
Compare
Render nested Thrift ARRAY, MAP and STRUCT values into a shared byte buffer instead of repeatedly copying growing strings, making wide results linear while preserving their existing text representation. Fixes #596 Signed-off-by: Vu Anh Phung <vu.phung@databricks.com> Co-authored-by: Isaac <no-reply@databricks.com>
ac22c3e to
867b4ce
Compare
Fix quadratic string concatenation when Thrift renders ARRAY, MAP and STRUCT results. Containers append recursively into one buffer; nested containers, including complex MAP keys, append to the caller's buffer, so no intermediate strings are built (this also covers #353's root cause). Each top-level container reuses its render buffer only while its capacity is at most 64 KiB and clears it on batch reload and release, so each complex column keeps at most 64 KiB and a large value no longer stays live after it is returned. Values whose render buffer grows past 64 KiB (from about 57 KB of ARRAY output, because append overshoots) regrow it on every row, which stays linear. Output is byte-for-byte unchanged, and scalar columns don't reach the changed code.
Verified 239 golden shape/type cases, including MAP with ARRAY and STRUCT keys at the top level and inside an ARRAY, against this branch and against
origin/main's renderer. New tests cover a large-then-small value per shape, a 50 KiB complex map key (the key container keeps no buffer; live heap after GC grows by one top-level buffer of at most 64 KiB), a value under 64 KiB that grew into a larger buffer, small values after runs of large ones, and rendering after an error in list elements, map keys (scalar and complex) and map values; the 5000-wide guard stays under 0.72 MB/render (16 MiB ceiling). Memory tests assert retained capacities directly and pass 100 of 100 fresh runs under-covermode=atomic. Live heap after GC, main vs this PR: 64 MiB value then small ones 0–224 B vs 16–128 B; 50 KiB complex key 0 B vs 57,344 B (one top-level buffer of at most 64 KiB); a STRUCT with four 40 KiB-keyed maps 16 B vs 96 B.make lint,make test,-race -shuffle=onand the kernel-tagged tests pass;-gcflags=-mshows only the result string and itsanyboxing escaping (plus the complex-key string, which replaces the stringkeys.Valuebuilt before). Live Thrift complex rendering, an over-64-KiB-then-small query, complex-keyed maps (identical text on main and this PR) and kernel/Thrift parity pass.Benchstat medians, main → this PR, 18 samples per version (three rotated fresh-process rounds of
-count=6 -benchtime=200ms,GOMAXPROCS=2). These are steady-state numbers for a warm container: every case is faster (p<0.001), and B/op is equal at width 0 and lower everywhere else. The first complex value in each record batch starts from an empty buffer and can cost a few bytes more than main at widths 0–2.Once the render buffer grows past 64 KiB (ARRAY width about 3400 and up, from about 57 KB of output), it isn't kept, so each row grows a new one: at widths 3800–5000, 372–699 KiB per render, about 6x the output including the result string, and more than 99.8% below main. MAPs with ARRAY keys are 27–61% faster than main.
Cross-driver state
StringBuilder; default string MAP formatting also uses a builder.EnableComplexDatatypeSupport=0;DatabricksArray.java:434,DatabricksMap.java:238,DatabricksStruct.java:282,ComplexDataTypeParser.java:676@b75bdb8.as_py();_disable_pandas=False.src/databricks/sql/result_set.py:97@75a0d5d. No growing JSON string loop.database/sqlsurface and scalar formatting unchanged; recursive append with at most 64 KiB kept per complex column replaces concatenation.toJSON()/map().lib/result/ArrowResultConverter.ts:455@d76fc08. No growing JSON string loop.internal/arrowscanalready renders linearly.Fixes #596
This pull request and its description were written by Isaac.