Skip to content

perf(vector): avoid eager varlen extraction for legacy collations - #30114

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/29571-varlen-copy-admission-20261013
Oct 13, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/29571-varlen-copy-admission-20261013

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

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 #29571; this does not close its remaining performance acceptance.

What this PR does / why we need it:

Ordinary string copies through BuildVarlenaFromVarlena eagerly call GetByteSlice before the collation validator determines that the value needs no native Unicode validation. This per-row work, introduced by #29601 after the earlier UnionOne fixes, remains visible in BigData sorted-write profiles.

Check the existing Unicode-domain predicate before extracting the value. Native Unicode values keep the same UTF-8/repertoire validation and rejection-before-write behavior. Copy ownership, allocation failure handling, disjoint-area proofs and serialization formats are unchanged.

Extend the existing collation tests with inline/area/empty copies, independent destination ownership, malformed UTF-8 and utf8mb3 repertoire rejection, and an opaque binary control. Add a copy benchmark with legacy and native Unicode controls.

Validation

Base: 35c8dd5854750ef96f52f9dd298a70acd031d5e4. Linux amd64, Go 1.27.1, GOAMD64=v3, GOEXPERIMENT=simd; native libraries rebuilt from this checkout using make -j8 cgo.

  • Baseline and candidate both pass the 11 admission/copy scenarios. Complete pkg/container/vector and pkg/objectio/mergeutil suites pass: 292 top-level tests, zero failures/skips. Existing real merge tests verify output order, exact values, reuse and owned-varlen serialization.
  • Changed package and merge consumer vet/lint pass; lint reports 0 issues. Final scope reviewed against Unicode admission and copy/ownership invariants.
  • Eight alternating baseline/candidate benchmark pairs on CPU 6, GOMAXPROCS=1, 500ms per sample, warmup excluded. Median times:
Benchmark Baseline Candidate Change
UnionOne, 8192 legacy inline strings 254.541 us 213.556 us -16.1%
UnionOne, 8192 legacy area strings 327.833 us 271.845 us -17.1%
Native Unicode inline control 386.490 us 387.803 us +0.34%
Native Unicode area control 511.261 us 510.652 us -0.12%
Existing overlapping merge + marshal consumer 1423.543 us 1350.171 us -5.15%

Copy benchmarks retain 0 B/op and 0 allocs/op; the merge benchmark retains 31 allocs/op. These are component measurements, not an asserted SQL or full-workflow speedup.

The unmodified base currently fails the full image build because EXPLAIN references removed protobuf fields, tracked by #30108 (existing fixes #30110/#30111). This is separate from the passing package validation above: baseline build failure.

A separate Q7-only diagnostic run uses the previously accepted main product 02a2823c and original 1B assets to isolate concurrent I3 workload effects. It does not contain or validate this PR.

@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 Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: a20f7eb6a00994caf2012a1d95d30b62e6cac396

Assessment: approve

Reviewed the complete two-file delta and affected callers. The optimization preserves Unicode admission, copy ownership, allocation failure behavior and serialization. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

Validation:

  • Verified frozen head, merge-base, patch and unchanged source. Isolation preflight passed; 192 native inputs and 62 retained artifacts independently matched.

  • Vector and mergeutil suites passed: 292 top-level tests, 399 subtests, zero failures or skips. Coverage includes all 11 new admission cases, ownership, allocation failure, reuse and merge/serialization.

  • Six alternating benchmark pairs against the merge-base implementation: legacy inline/area copies improved 9.5%/10.2%; overlapping merge plus marshalling improved 6.0%. Allocation counts remained unchanged.

  • Frozen CI metadata reports successful shared build, Ubuntu UT, SCA and Compose BVT checks.

  • Commands, source fingerprints, terminal receipts and logs reconciled in /home/xupeng/.local/state/mo-bot/jobs/0d750415b75a1eb0c5741c5c/attempt-1/validation-audit.json; review coverage recorded in review-record.json.

Limitations:

  • Unicode benchmark controls were 1.7–1.9% slower locally; accepted as a small measured tradeoff against the legacy-copy and merge gains.

  • Measurements establish component performance, not SQL or full BigData speedup. Issue [Bug]: UnionOne regresses indexed-write copy and varlen marshal performance vs 4.2 #29571's broader acceptance remains open; its body was absent from frozen evidence.

  • CI evidence contains status metadata without raw logs. Author measurements used an earlier base; this assessment relies on the independent local comparison.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

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: a20f7eb6a00994caf2012a1d95d30b62e6cac396

Assessment: approve

Reviewed the complete two-file delta and affected callers. The optimization preserves Unicode admission, copy ownership, allocation failure behavior and serialization. No actionable defects remain.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

Validation:

  • Verified frozen head, merge-base, patch and unchanged source. Isolation preflight passed; 192 native inputs and 62 retained artifacts independently matched.

  • Vector and mergeutil suites passed: 292 top-level tests, 399 subtests, zero failures or skips. Coverage includes all 11 new admission cases, ownership, allocation failure, reuse and merge/serialization.

  • Six alternating benchmark pairs against the merge-base implementation: legacy inline/area copies improved 9.5%/10.2%; overlapping merge plus marshalling improved 6.0%. Allocation counts remained unchanged.

  • Frozen CI metadata reports successful shared build, Ubuntu UT, SCA and Compose BVT checks.

  • Commands, source fingerprints, terminal receipts and logs reconciled in /home/xupeng/.local/state/mo-bot/jobs/0d750415b75a1eb0c5741c5c/attempt-1/validation-audit.json; review coverage recorded in review-record.json.

Limitations:

  • Unicode benchmark controls were 1.7–1.9% slower locally; accepted as a small measured tradeoff against the legacy-copy and merge gains.

  • Measurements establish component performance, not SQL or full BigData speedup. Issue #29571's broader acceptance remains open; its body was absent from frozen evidence.

  • CI evidence contains status metadata without raw logs. Author measurements used an earlier base; this assessment relies on the independent local comparison.

@mergify mergify Bot added the queued label Oct 13, 2026
@mergify

mergify Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-13 14:00 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-10-13 14:00 UTC · at 47bbf28c0551134feffbee636ab0c2306c27971d · squash

This pull request spent 15 seconds in the queue, including 1 second running CI.

Required conditions to merge

XuPeng-SH pushed a commit that referenced this pull request Oct 16, 2026
…ion (#30284)

## 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 #29755. This is a partial performance repair, not a claim
that the remaining BigData regression is fully resolved.

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

Reduce repeated writeback work in bounded HashBuild spill writes and
repeated metadata scans in JOIN recovery without removing memory, disk,
or FD admission.

- Keep main's per-physical-write FD lifetime: each write closes its
descriptor and returns its FD reservation. Cross-write FD caching has
been withdrawn because local eviction cannot protect mandatory admission
by other spill owners sharing the query/CN budget.
- Allow a fully memory-accounted 4 MiB write-cache window when admission
permits, retaining the 256 KiB fallback. Submit writeback in bounded
ranges and submit all tails before waiting at handoff. Return writer
cache charges before recovery readers are admitted.
- Observe GROUPING key metadata incrementally for each recovery bucket
instead of rescanning all retained batches for every input record.
Observe the pending input before copying, including a late GROUPING
sentinel.

Cross-write FD reuse, the conditional post-copy-check optimization, and
all newly added sampled diagnostics/worker logs have been removed from
this PR. Recovery retains main's per-input pre-copy AND post-copy budget
checks. Physical allocation admission remains authoritative. No
cross-owner reclamation mechanism or new FD admission API is introduced.

No planner, statistics, SQL, spill-record format, DOP, benchmark-input,
or resource-limit changes. The legacy varlena-copy optimization is
already on main through #30114 and is not duplicated here. The
experimental EXPLAIN build repair is also excluded. Diagnostic fixtures,
raw profiles, investigation documents, and harness changes stay outside
this PR. Logical spill-record coalescing remains a future experiment and
is not included.

Historical measurements from the unchanged TKE I3 + Q7 workload, not
current-head results (3 CNs, each 14 CPU / 55 GiB; original
SQL/data/concurrency and default spill settings):

| Measured revision/run | I3 INSERT | Q7 sum of 60 SQL durations |
| --- | ---: | ---: |
| Original pre-#29646 main,
[37489307309](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/37489307309)
| 88.817 min | 140.255 min |
| Earlier experimental revision `d9b972252b`,
[38379899443](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/38379899443)
| 106.472 min | 137.366 min |
| Incremental projection + varlena repair, [38534959447 attempt
2](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/38534959447/attempts/2),
`3331b03b27` | 96.042 min | 130.399 min |
| Latest experimental revision,
[38675199995](https://github.com/matrixorigin/mo-nightly-regression/actions/runs/38675199995),
`9316d94277` | 95.942 min | 131.458 min |

The latest run passed I3 result comparison and all 60 Q7 checks.
Relative to the earlier experimental revision, I3 elapsed time decreased
by 9.9%; relative to the original baseline, I3 remains 8.02% slower and
Q7 is 6.27% faster. The 153.63-minute I3 result reported in #29755 is
historical context, not a matched control for this PR. I3 and Q7
overlap, so these durations must not be added as suite wall time.

These are single-run historical comparisons, not isolated speedups
attributable entirely to this diff: the earlier-to-latest improvement
also includes the varlena repair now in main. The final redundant-check
change alone produced no meaningful whole-query speedup (I3 5762.514 ->
5756.537 seconds). The remaining I3 regression is still under
investigation.

Component evidence: incremental projection over 8192 retained prefixes
reduced 106.458 ms to 0.120 ms with zero allocations. This establishes
the local mechanism, not a predicted SQL percentage. The earlier
combined writer benchmark included FD reuse and is no longer presented
as evidence for the remaining writeback implementation.

Delivery is based on main `76deafc806`. Only bounded writeback
amortization and incremental recovery projection remain. The
full-workload numbers above were collected on the named experimental
revisions, which included FD reuse and diagnostic instrumentation,
before this delivery cleanup. They are not an exact-current-head
full-workload measurement or a fresh comparison against today's main.
Removing FD reuse gives up its potential reopen/seek/close savings;
current-head end-to-end BigData/TPCH/TPC-DS performance has not been
measured.

The retained tests cover finite shared query/CN FD caps across spill
owners, optional cache-memory fallback, cancellation and failed handoff,
exact read-back and terminal charges, and late GROUPING sentinels with
per-bucket reset. Diagnostic-only assertions/benchmarks, optional-FD
admission tests and the test specific to conditional post-copy checks
have been removed with their implementations. Main's mandatory FD
admission tests remain. No benchmark wall-time assertions or large
diagnostic fixtures were added to unit tests.

Review repair (`ca3fda5588`): cross-owner FD caching is withdrawn,
rather than introducing a shared eviction mechanism. Both
same-generation and cross-generation pressure regressions failed before
the repair with `requested=1 used=2 cap=2` and pass afterward. The tests
retain a real active-reader FD, exercise both writers and handoff, and
verify exact bytes and resource charges. HashBuild's physical-write path
and mandatory FD admission are restored to main; batch writeback and
incremental projection remain.

Current validation: native artifacts rebuilt successfully through the
repository build owner; 8 owning/consumer packages passed normal tests
with vet; 4 related packages passed race; the new cross-owner regression
passed 100 race repetitions; incremental lint reported 0 issues. New
remote CI is pending. No exact-head whole-workload performance result is
claimed.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
ci — a20f7eb6 Deployed Oct 13, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants