Repository navigation
perf: avoid repeated TEXT assignment buffer growth - #32771
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
This pull request is merged. |
|
mo-bot review · Commit: Review discussion changed before publication; a fresh contextual review is queued. |
Independent QA challenge (base
|
| Scenario | Base | Head | Delta |
|---|---|---|---|
| Four external fields | 1888.5 ns | 961.3 ns | -49.1% |
| 8 MiB field first + 31 × 64 KiB | 1.441 ms | 0.719 ms | -50.1% |
| 8 MiB field last + 31 × 64 KiB | 1.490 ms | 0.714 ms | -52.1% |
| Small reused result | 165.65 ns | 172.0 ns | +3.8% (~6.35 ns) |
Cumulative MPool allocation volume decreased from 18,883,328 to 10,420,992 bytes for large-first (-44.8%) and from 21,693,184 to 10,420,992 bytes for large-last (-52.0%). The small reused-result path shows a modest local regression, which looks like a performance tradeoff rather than a correctness blocker.
Validation boundary
I did not independently rerun SQL LOAD/ALTER row hashes, process-level RSS measurements, or a two-CN deployment; those remain covered by the PR validation and CI rather than by this local run. At the time of this comment, Ubuntu UT/coverage, SCA, and the two Compose multi-CN BVT jobs are still pending.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 2c0bbe9e0299f5375872cc641f49c3fed81528df
Assessment: approve
The guarded reservation preserves assignment and ownership contracts while reusing existing Vector/MPool owners. Verified allocation savings justify the extra passes and modest small-path overhead; the new QA discussion introduces no unresolved blocker.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
Validation:
-
Reverified 17 same-head checks against retained receipts/logs: nine added test roots, owning-package normal/race tests, 100 exact-reader race repetitions, static checks and baseline/candidate probes. Evidence is indexed in validation-ledger.json; product executions were reused.
-
Public-entry probes show four area allocations becoming one and large-case allocation volume falling from 18.9–21.7 MB to 10.4 MB. Retained ABBA cold-large benchmarks improved 47–52%.
-
Fresh source/evidence audit passed: 195 native input fingerprints match, all five discussion keys are assessed, and the frozen source remains unchanged.
Limitations:
-
Five hosted-CI checks remain pending; eight optional ONNX tests skipped in the reused owning-package runs.
-
Retained Linux small-control medians were 2.5–6.2% slower (23–95 ns per eight-row cast), without added allocations; accepted as a bounded tradeoff.
-
The new macOS/arm64 QA and SQL/RSS observations are author-reported. SQL/RSS and multi-CN checks were not rerun; whole-query memory and idle RSS remain outside the demonstrated component benefit.
## What type of PR is this? - [ ] API-change - [ ] 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: The object writer currently compresses into a separate scratch buffer and then copies the compressed bytes into the writer arena. When the unused arena tail already fits the LZ4 compression bound, that creates an avoidable live allocation and copy. Compress directly into the unused tail when it is large enough and does not overlap the input. Commit only the actual compressed length to the arena after success. Inputs overlapping the tail, insufficient space, and writers without an arena keep the existing scratch path. The LZ4 format, extent metadata, ownership of completed output, and arena accounting remain unchanged. Validation on a CPU-only 57 host: - Exact compressed bytes, offsets, NULLs, multiple sequential writes, alias and insufficient-capacity fallback, and an in-memory object write/read after arena reuse were checked. The full objectio package passed normally and under race; the independent concurrent-arena test passed 100 race repetitions. Incremental lint and formatting passed. - In two isolated 1-CN LOAD/ALTER cases (one 8 MiB field and 31 64 KiB fields, large field first or last), all row hashes and strict/non-strict diagnostics matched. The load-idle native profile dropped the 16 MiB compression scratch while retaining the 32 MiB arena. Sampled LOAD RSS deltas changed 115.13→105.11 MiB and 106.39→95.11 MiB; one run per order with 5 ms sampling is not an exact peak or a production-scale estimate. - Combined with merged #32771, an additional 1-CN case preserved all hashes and diagnostics. Its sampled LOAD/ALTER RSS deltas were 96.68/34.46 MiB versus 115.13/50.46 MiB in the separate base run; profile attribution confirms both allocation reductions, but individual runs are not directly additive. - Three alternating microbenchmark rounds showed little change for 64 B–4 KiB serial inputs and about 52% lower time for 8 MiB varied input in the direct path. A four-producer 4 KiB case was 1.3% slower. The initial 8 MiB fallback samples were 4–6% slower; eight additional alternating pairs had a +0.39% median with several-percent variation. These shared-host samples do not prove a universal no-regression result. Rows whose compression bound exceeds the unused arena capacity retain the existing path; this alone does not resolve the original very-large-row OOM. ## Overlap guard and SCA follow-up - `unsafe` is confined to `compression_overlap.go`, which compares addresses without dereferencing or reconstructing pointers. The caller must keep both buffers and their owners valid and must not release the arena concurrently. `writer.go` remains subject to the unsafe-import check. Empty, same-start, containment, both partial-overlap directions, adjacent and separate slices are tested; real compression tests verify that overlapping input falls back and adjacent input uses the direct path. - The pinned molint is the official master commit `147a3f213653` merged in [linter PR 57](matrixorigin/linter#57); it no longer depends on the unmerged compatibility branch. Compared with the previous MatrixOne main pin, this version also includes three function-scoped `recover` approvals already merged in [linter PR 56](matrixorigin/linter#56). - The complete `pkg/objectio` suite passed normally and under race on the earlier PR head. After merging the latest main including #32782, compression and S3 writer/cache interaction tests passed under race, and the official merged molint plus golangci passed `make static-check-selected STATIC_CHECK_PACKAGES=./pkg/objectio` on commit `11e75981aa3ce38812484cb533c093be89bf9260`. Full CI is running on that head. The linter itself passed `go test ./...` before merge. - Comparing the guard extraction against the earlier PR head on the shared 57 host, the first three-pair 64-byte sample had a +3.35% median; six additional alternating pairs had a -0.23% paired median. The 4 KiB follow-up paired median was +0.09%. These short samples are noisy and do not establish a universal performance result.
What type of PR is this?
Which issue(s) this PR fixes:
Related to #32751
What this PR does / why we need it:
A new TEXT/BLOB assignment result can repeatedly grow its payload area as large fields are appended. During operations such as ALTER's table copy, old and new buffers coexist and increase transient CN memory use.
For eligible empty, independently owned results, preflight the selected source values and reserve the required payload area once. Width or collation violations, partial selection, aliases, existing capacity, unsupported vector shapes, and allocations beyond the allocator's single-allocation limit keep the original path. The assignment still owns its output, and existing truncation, warning, error, and NULL behavior is preserved.
Validation on a CPU-only 57 host:
pkg/sql/plan/functiontests and package race test; focused race tests and 100 repeated concurrent-reader runs; incremental lint and format checks.