Allocate fresh map on reconstruction to prevent stale entry leaks
perfloop-oss/parquet-go · Uncatalogued correctness
https://perfloop.ai/t/oss/case_maha88wjfp
Verdict
VERIFIED · settled 2026-11-25 · merged as parquet-go/parquet-go#770
What happened: The check fails before this change and passes with it.
Hypothesis
Reconstructing a Parquet map column into a reused destination slice silently merges entries from the previous row into the new row and mutates any map retained from the earlier read. Callers using standard `GenericReader[T].Read` batch loops reuse one `[]T` buffer across calls, and `GenericReader.Read` documents that returned values are safe to reuse across `Read` calls. Production prevalence is unmeasured.
In `row.go:1011-1015`, `reconstructFuncOfMap` only allocates a new map when `value.IsNil()`. When a destination struct field already holds a non-nil map from an earlier `Read` call, `reconstructFuncOfMap` inserts the new row's keys directly into that existing map via `value.SetMapIndex`. By contrast, `reconstructFuncOfOptional` (`row.go:834-840`) explicitly allocates a fresh pointer on every read to avoid mutating retained values (issue #522), and `reconstructFuncOfGroup` (`row.go:1117-1119`) replaces non-empty maps.
A bounded check over three row-pair shapes (disjoint non-empty maps, overlapping keys with stale keys, and non-empty followed by empty) found 4 failures across both non-empty transitions: reading `{"a": 1, "b": 2}` then `{"c": 3}` into a reused 1-element `[]mapReuseRow` buffer yields `map[a:1 b:2 c:3]` for row 1 and mutates the retained row 0 map to `map[a:1 b:2 c:3]`.
Current open upstream PRs (read 2026-11-24) do not modify `row.go`; PR #730 adds `GenericReader.Iter` and explicitly clears each reused slot to work around map reuse in its own iterator buffer, leaving `GenericReader.Read` and `Schema.Reconstruct` affected.
The Case proof target is to ensure `reconstructFuncOfMap` produces exact, isolated maps for every row without leaking stale entries or mutating previously returned rows when destination buffers are reused across `Read` and `Schema.Reconstruct` calls, including `any`/interface map targets, confirmed by the deterministic replay and expanded reuse matrix (provisional layout).
Change to test: Allocate a fresh map in reconstructFuncOfMap instead of mutating a non-nil destination map in place, matching the non-aliasing guarantee of GenericReader.Read and reconstructFuncOfOptional, and add regression tests for reused Read buffers and retained rows.
Where it lives
perfloop-oss/parquet-go · reader.go
Evidence
The check fails before this change and passes with it: `For successive valid rows with required maps, Schema.Reconstruct and GenericReader.Read into reused one-element destination buffers return exactly each row's map entries and preserve maps retained from earlier rows, for typed and any-valued map fields.`
Schema.Reconstruct string map · 42 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
340.6 |
381.4 |
+11.5% (+39.25) |
+10.2 to +54.7 |
loss ≤ 0.17 × |baseline median| |
PASSED |
B/op |
48 |
256 |
+433.3% (+208) |
+208 to +208 |
loss ≤ 4.34 × |baseline median| |
PASSED |
allocs/op |
3 |
2 |
−33.3% (−1) |
−1 to −1 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct integer-key map · 27 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
333.6 |
396.9 |
+57.4 |
−45.1 to +118.8 |
loss ≤ 0.38 × |baseline median| |
PASSED |
B/op |
44 |
256 |
+481.8% (+212) |
+212 to +212 |
loss ≤ 4.82 × |baseline median| |
PASSED |
allocs/op |
3 |
2 |
−33.3% (−1) |
−1 to −1 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct binary-value map · 53 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
378.1 |
470.6 |
+23.6% (+89.2) |
+44.9 to +132 |
loss ≤ 0.37 × |baseline median| |
PASSED |
B/op |
89 |
401 |
+350.6% (+312) |
+312 to +312 |
loss ≤ 3.51 × |baseline median| |
PASSED |
allocs/op |
4 |
3 |
−25% (−1) |
−1 to −1 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct list-value map · 53 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
669.8 |
785.9 |
+16.6% (+111.3) |
+67.1 to +173.5 |
loss ≤ 0.28 × |baseline median| |
PASSED |
B/op |
136 |
472 |
+247.1% (+336) |
+336 to +336 |
loss ≤ 2.48 × |baseline median| |
PASSED |
allocs/op |
7 |
7 |
0 |
0 to 0 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct nested map · 405 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
791.6 |
804.5 |
+1.6% (+12.5) |
+1.3 to +23.8 |
loss ≤ 0.03 × |baseline median| |
PASSED |
B/op |
352 |
560 |
+59.1% (+208) |
+208 to +208 |
loss ≤ 0.6 × |baseline median| |
PASSED |
allocs/op |
8 |
6 |
−25% (−2) |
−2 to −2 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct optional map · 159 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
353.6 |
398.4 |
+12.8% (+45.2) |
+36.5 to +58.8 |
loss ≤ 0.17 × |baseline median| |
PASSED |
B/op |
48 |
256 |
+433.3% (+208) |
+208 to +208 |
loss ≤ 4.34 × |baseline median| |
PASSED |
allocs/op |
3 |
2 |
−33.3% (−1) |
−1 to −1 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct optional-value map · 17 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
387.9 |
436 |
+11.9% (+46.2) |
+9.7 to +62.3 |
loss ≤ 0.33 × |baseline median| |
PASSED |
B/op |
56 |
264 |
+371.4% (+208) |
+208 to +208 |
loss ≤ 3.72 × |baseline median| |
PASSED |
allocs/op |
4 |
3 |
−25% (−1) |
−1 to −1 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct null-value map · 57 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
349.3 |
396.9 |
+13.9% (+48.7) |
+13.1 to +89.1 |
loss ≤ 0.3 × |baseline median| |
PASSED |
B/op |
48 |
256 |
+433.3% (+208) |
+208 to +208 |
loss ≤ 4.34 × |baseline median| |
PASSED |
allocs/op |
3 |
2 |
−33.3% (−1) |
−1 to −1 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct empty-list-value map · 131 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
521.7 |
686.3 |
+32.1% (+167.3) |
+132 to +205.5 |
loss ≤ 0.42 × |baseline median| |
PASSED |
B/op |
112 |
448 |
+300% (+336) |
+336 to +336 |
loss ≤ 3.01 × |baseline median| |
PASSED |
allocs/op |
4 |
4 |
0 |
0 to 0 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct wide map · 36 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
20896 |
19096 |
−1387 |
−3643 to +743 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
B/op |
6724 |
9565 |
+42.3% (+2841) |
+2840 to +2842 |
loss ≤ 0.43 × |baseline median| |
PASSED |
allocs/op |
321 |
260 |
−19% (−61) |
−61 to −61 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
GenericReader.Read four-key row · 40 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
1106 |
923.9 |
−188.8 |
−364.2 to +14 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
B/op |
152 |
288 |
+89.5% (+136) |
+136 to +136 |
loss ≤ 0.9 × |baseline median| |
PASSED |
allocs/op |
13 |
6 |
−53.8% (−7) |
−7 to −7 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Reader.Read four-key row · 28 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
1101 |
944.5 |
−15.4% (−169.4) |
−338.3 to −15 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
B/op |
152 |
288 |
+89.5% (+136) |
+136 to +136 |
loss ≤ 0.9 × |baseline median| |
PASSED |
allocs/op |
13 |
6 |
−53.8% (−7) |
−7 to −7 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
GenericReader.Read map batch · 18 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
135242 |
110793 |
−26455 |
−67321 to +2906 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
B/op |
19526 |
36943 |
+89.2% (+17419) |
+17409 to +17425 |
loss ≤ 0.9 × |baseline median| |
PASSED |
allocs/op |
1664 |
768 |
−53.8% (−896) |
−896 to −896 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
GenericReader.Read singleton map · 41 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
437.8 |
514.6 |
+15.5% (+68) |
+16.6 to +122.6 |
loss ≤ 0.3 × |baseline median| |
PASSED |
B/op |
48 |
256 |
+433.3% (+208) |
+208 to +208 |
loss ≤ 4.34 × |baseline median| |
PASSED |
allocs/op |
3 |
2 |
−33.3% (−1) |
−1 to −1 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Reader.Read singleton map · 37 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
441.2 |
517.9 |
+16.8% (+74.3) |
+25.2 to +138.2 |
loss ≤ 0.34 × |baseline median| |
PASSED |
B/op |
48 |
256 |
+433.3% (+208) |
+208 to +208 |
loss ≤ 4.34 × |baseline median| |
PASSED |
allocs/op |
3 |
2 |
−33.3% (−1) |
−1 to −1 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
GenericReader.Read 100k map rows · 29 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
231131320 |
180629185 |
−22.3% (−51486286) |
−85127685 to −43185933 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
B/op |
69041136 |
95288296 |
+38% (+26247336) |
+25575832 to +27238960 |
loss ≤ 0.4 × |baseline median| |
PASSED |
allocs/op |
3262138 |
1376228 |
−57.8% (−1885919) |
−1885943 to −1885864 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
GenericReader.Read one-row map batch · 19 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
507.4 |
570.6 |
+69 |
−9.9 to +145 |
loss ≤ 0.39 × |baseline median| |
PASSED |
B/op |
65 |
273 |
+320% (+208) |
+208 to +209 |
loss ≤ 3.27 × |baseline median| |
PASSED |
allocs/op |
4 |
3 |
−25% (−1) |
−1 to −1 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
GenericReader.Read four-key 128-row batch · 19 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
167128 |
147581 |
−17820 |
−41404 to +834 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
B/op |
36985 |
55689 |
+51.1% (+18912) |
+17037 to +20137 |
loss ≤ 0.58 × |baseline median| |
PASSED |
allocs/op |
1666 |
770 |
−53.8% (−896) |
−896 to −896 |
no regression (noise ≤ 0.05 × |baseline median|) |
PASSED |
Schema.Reconstruct boolean-value map · 38 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
368.6 |
476.8 |
+25.9% (+95.3) |
+58.6 to +147.2 |
loss ≤ 0.44 × |baseline median| |
PASSED |
B/op |
41 |
256 |
+524.4% (+215) |
+215 to +215 |
loss ≤ 5.25 × |baseline median| |
PASSED |
Schema.Reconstruct float64-value map · 65 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
350.8 |
399.9 |
+13.4% (+47) |
+13.6 to +77.7 |
loss ≤ 0.24 × |baseline median| |
PASSED |
B/op |
48 |
256 |
+433.3% (+208) |
+208 to +208 |
loss ≤ 4.34 × |baseline median| |
PASSED |
Schema.Reconstruct fixed-array-value map · 19 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
ns/op |
365.5 |
416.8 |
+38.3 |
−16.1 to +110.1 |
loss ≤ 0.5 × |baseline median| |
PASSED |
B/op |
44 |
256 |
+481.8% (+212) |
+212 to +212 |
loss ≤ 4.82 × |baseline median| |
PASSED |
Checks: 3 of 3 passed. Verification: no defect found.