Skip to content

fix(pSpool): reserve batch backing without planning slices - #32754

Merged
XuPeng-SH merged 4 commits into
mainfrom
codex/32751-batch-cache-main
Nov 15, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
codex/32751-batch-cache-main

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #32751.

What this PR does / why we need it:

Reserve cached backing across the uncopied batch suffix without allocating request or copy-index slices. After caching [empty, 128 MiB], copying [1 MiB, 128 MiB] previously let the small column consume the only large block. The revised real-Vector diagnostic uses about 129 MiB target native backing/peak instead of 256 MiB, preserving every payload byte. This is a component result, not a CN RSS/OOM claim. 4.2-dev counterpart: #32758.

Exact compatible hits and current needs that dominate future needs can reuse backing directly. Other needs are visited largest-first through a constant-size cursor, followed by source-order undersized fallback. Best-fit searches first reject insufficient or already-worse capacities before checking allocation provenance; the chosen block, tie order and attachment checks are identical. Logical needs replace historical spare backing size. Payloads and borrowed snapshots remain in source order. There is no retained planning state, new pool or configuration. Worst-case matching work remains O(N² + N·B).

The mixed-shape native-retention assertion is restored across eight shapes. Values, NULL/constants/nil, aliases and allocation failure after an already copied prefix -> slot return -> retry remain covered. Add smallest-sufficient and alias-boundary controls; both pools must reach zero. The borrowed snapshot peak test includes an alias and protects main base's already-correct behavior. A separate full-orchestration oracle passes 1,728 combinations; the 128 MiB resident-page probe stays outside CI.

Validation on machine 57, CPU-only, Go 1.27.1: full pSpool/connector/dispatch normal and race UTs; scoped vet; incremental golangci-lint (0 issues); real-Vector memory diagnostic and independent matching oracle all pass after the final predicate change. Earlier public-API round-trip/slot-reuse/snapshot/terminal QA passed 10 race repetitions; that public API and its ownership path are unchanged.

Local fixed8192/four-producer recheck on cores 0-3 (one L3), six 1-second samples per revision: base median 303.15 ns/op, prior revision 307.20, final 305.50 (+0.78% vs base), unchanged B/op and allocs/op. Cross-L3 results vary substantially: an initial +10% result did not persist in the repeat. A full concurrent benchmark round overlapped unrelated Rust compilation and is excluded from acceptance. The maintained benchmark covers 10 fixed/exact/spare/changing/wide/bulk shapes, with independent source/cache/MPool ownership per producer.

Rebased onto main d1893e5ae7. Keep draft pending stable concurrent/cross-hardware performance review and CI at the final head. Local measurements do not establish query p99, whole-CN memory recovery or universal performance acceptance.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: d751ba11a103a4bc1dccd0a6012178331446773f

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: d751ba11a103a4bc1dccd0a6012178331446773f

Assessment: request_changes

Batch-wide matching fixes cached-capacity waste and reuses existing provenance and cleanup owners. One allocation-order regression remains: preparing borrowed snapshots early increases peak demand and rejects batches that fit on the baseline.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

  • P2 pkg/container/pSpool/copy.go:119: An earlier ordinary column must grow cached backing, while a later borrowed varlen column owns descriptors that must be copied, and the target pool has limited headroom.
    Impact: RetainedReadonlyViewWithMP now allocates those later descriptors before the earlier column grows and releases its old buffer. Previously successful copies fail with an allocation error that propagates through SendBatch. Defer borrowed-snapshot allocation to the source-order copy phase while preserving batch-wide buffer reservation, and add a mixed-path headroom regression.
    Evidence: A retained 512-row probe gives a valid 1 MiB pool 42,240 bytes of headroom: warmed backing is 20,480 bytes, area growth needs 13,568 bytes, and later borrowed descriptors need 12,288 bytes. The actual baseline passes with 38,144 final bytes; the candidate fails with 'mpool physical capacity exceeded'. See borrowed-headroom-baseline.log, borrowed-headroom-candidate-v2.log and receipt/artifact mappings in review-evidence.json. buffer_lease.go:422 allocates the descriptors; mpool.go:1513 allocates replacement backing before freeing the old allocation.

Validation:

  • Source/patch identity, formatting, native CPU build/provenance and final evidence audits passed; the assigned source remains unchanged.

  • Linux amd64, Go 1.27.1: full pSpool tests passed with -count=1 in normal and -race modes (pspool-normal.log, pspool-race.log).

  • Full connector and dispatch normal tests passed after resuming an initial dependency/build timeout (consumers-normal-resume.log).

  • Mixed-path probe: actual baseline passed; candidate reproduced the allocation regression. Intended reservation control failed on the baseline and passed on the candidate.

  • All three discussion keys are accounted for in discussion-assessment.json; review-evidence.json reconciles retained logs, receipts and input hashes.

Limitations:

  • Frozen CI build/UT/static-analysis checks were still in progress.

  • Author-reported large-payload and microbenchmark measurements were not independently repeated; no whole-CN/RSS benefit is established by this review.

@XuPeng-SH
XuPeng-SH marked this pull request as draft November 15, 2026 00:36
@XuPeng-SH
XuPeng-SH force-pushed the codex/32751-batch-cache-main branch from d751ba1 to 1b28d36 Compare November 15, 2026 01:45
@XuPeng-SH XuPeng-SH changed the title fix(pSpool): reserve cached backing across batch columns perf(pSpool): stop cache scans after an exact fit Nov 15, 2026
@XuPeng-SH
XuPeng-SH marked this pull request as ready for review November 15, 2026 01:48
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Nov 15, 2026
@XuPeng-SH XuPeng-SH changed the title perf(pSpool): stop cache scans after an exact fit fix(pSpool): reserve batch backing without planning slices Nov 15, 2026
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH

XuPeng-SH commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: d59e1d93333dcfafd5071a9652b83b25605cb6a4

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: d59e1d93333dcfafd5071a9652b83b25605cb6a4

Assessment: request_changes

The component design reuses the existing DetachedBuffer owner and destination capacities to reserve sufficient backing, without new retained planner state. Source-order payload copying, borrowed snapshots, provenance and failure cleanup are preserved; the earlier borrowed-peak concern is resolved. The restored reservation addresses the documented mixed-shape amplification, but the explicitly retained concurrent-performance and cross-machine acceptance gate remains open. This is a validation gap, not a demonstrated production regression.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

  • P2 pkg/container/pSpool/copy.go:233: Accepting the restored batch-wide matcher for concurrent producers and changing multi-column batches before the P2/P2a performance gate in linked issue #32751 is closed.
    Impact: The new suffix preparation and O(N² + N·B) matching work has no accepted concurrent comparison for the affected wide/changing/bulk paths. The reported final main comparison measures fixed_8192, a one-column control that returns through the existing final-column selector; it cannot establish the cost of reservation. This leaves the explicitly required component acceptance unresolved, without proving a CPU regression.
    Evidence: The frozen PR body keeps the PR draft pending stable concurrent/cross-hardware review. Linked #32751 explicitly retains separate stable concurrent-performance and cross-machine fixed-path gates, excludes the Rust/clippy-contaminated full concurrent round, and says the earlier other-machine result needs a final-revision repeat. The single-L3 fixed_8192 report is 303.15 -> 305.50 ns/op (+0.78%, unchanged allocation counts); benchmark lines 37 and 44-46 distinguish that control from the affected cases. Close the gate with isolated baseline/candidate independent-producer comparisons for the affected shapes and the requested final-revision other-machine fixed control, recording matched settings, allocations, terminal results and the acceptance conclusion. Whole-CN RSS, query p99 and the unrelated P3-P7 work are outside this request.

Validation:

  • Read all four changed files, the complete frozen delta, all nine discussion entries and linked issue #32751; traced merge-base behavior, SendBatch/CacheBatch ownership, aliases, source-order borrowed snapshots, DetachedBuffer provenance and partial-failure cleanup.

  • PASS: source-transcribed finite matching model against an independent exhaustive sufficient-assignment oracle, 28,288 cases across three area columns, paired data/area requests and accounted backing kinds. Also verified clean exact HEAD and supplied patch equivalence to the frozen Git delta (terminal newline ignored). Receipt checks/1794726971701612732-2.json, log reservation-model.log, inputs reservation_model.py and reservation-model-result.json.

  • PASS: gofmt for all four changed Go files and stored PR template headings/LF checks. Receipt checks/1794727012758125982-2.json, log static-audit.log.

  • Author-reported evidence in the frozen PR body: final native normal/race pSpool, connector and dispatch suites; scoped vet/lint; independent-producer fixture smoke; real-Vector mixed-shape/peak diagnostics and a 1,728-case oracle. These reports support the functional analysis and are attributed, not claimed as new local execution.

Limitations:

  • No local native Go suites or throughput benchmarks were executed in this review; raw author command logs/native provenance were not supplied in local_validation, which is empty. The finite model does not execute Vector allocation, leases, copying, failure injection or concurrency.

  • Hosted product CI was pending/cancelled in the supplied snapshot; CI Required was FAILURE without a supplied causal product log. Neither is treated as a product pass or a demonstrated product defect.

  • The review covers the scoped pSpool P2 change, not whole-CN RSS/OOM improvement or closure of the broader linked tracker. No SQL, persisted format, protocol or upgrade contract changes.

XuPeng-SH added a commit that referenced this pull request Nov 15, 2026
…32758)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #32751.

## What this PR does / why we need it:

Preserve batch-wide large-buffer reuse while removing per-batch planning
slices and correcting undersized-fallback order. Seed `[1 KiB, empty]`,
then `[2 KiB, 4 KiB]` previously peaked at **7,216 B** because the old
block was released late; source-order fallback now peaks at **6,192 B**.
The `[1 MiB, 128 MiB]` real-Vector diagnostic retains about **129 MiB
target native backing/peak**. Main counterpart: #32754.

Exact hits and current needs that dominate future needs reuse backing
directly. Other needs are visited largest-first through
source/destination fields and a constant-size cursor, followed by
source-order undersized fallback. Best-fit loops reject insufficient or
already-worse capacities before checking allocation provenance. Both
predicates are read-only; selection/tie order and AttachTo's validation
are preserved. There are no request/copy-index slices, sorting
workspace, new pools or retained planning references. Worst-case work
remains O(N² + N·B).

Restore the mixed-shape native-retention assertion across eight shapes.
Preserve complete values/NULL/constants/nil/aliases and physical-budget
failure after a copied prefix -> slot return -> retry.
Smallest-sufficient backing and prefix/current/future alias controls
pass; both pools reach zero. A separate brute-force diagnostic passes
1,728 orchestration combinations against maximum covered need and
minimum sufficient capacity.

The final predicate-order change addresses the prior serial
wide-changing CPU regression. Machine 57, Go 1.26.4, six samples per
revision for 128 alternating-size columns: base median **98,438.5
ns/op**, prior revision 102,937, final **93,092 (-5.4% vs base)**. Go
cost remains **45,312 -> 29,696 B/op**, **389 -> 384 allocs/op** (~34.5%
fewer Go allocation bytes). Four-producer results remain sensitive to
topology and concurrent host work; a complete run overlapped unrelated
Rust compilation. Do not treat those runs as final concurrent acceptance
or infer that wide queries have low internal DOP.

After the final code change, full pSpool/connector/dispatch normal and
race UTs, scoped vet, incremental lint (0 issues), native 129 MiB
diagnostic and independent matching oracle all pass. Earlier public-API
spool QA passed 10 race repetitions; the public ownership path is
unchanged. The actual 4.2-dev base fails the 7,216 <= 6,192 growth
guard; the candidate passes without relinquishing the large-buffer
saving.

Base: `ad39691b6b`. Keep draft pending stable concurrent-performance
review and final-head CI. These component tests do not establish CN RSS,
query p99, idle recovery or an OOM fix.

This branch was successfully deployed

No deployments
ci — b256a3c9 Deployed Nov 15, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants