Skip to content

perf(container): optimize appends, validity ranges and typed reads - #30160

Merged
XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
Lundomn:codex/container-append-bulk-20261014
Oct 16, 2026
Merged

XuPeng-SH merged 9 commits into
matrixorigin:mainfrom
Lundomn:codex/container-append-bulk-20261014

Conversation

@Lundomn

@Lundomn Lundomn commented Oct 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:

Fixes #30175.

Related to #24097 (query-execution performance umbrella); this PR does not close the umbrella issue.

What this PR does / why we need it:

Vector append and read paths perform redundant per-row work. Borrowed Arrow validity range queries also scan individual bits. This PR reduces that work while preserving API, NULL, metadata, aliasing, type-check and serialization behavior. It also addresses CI-exposed service-publication and test-cleanup lifecycle problems described below.

  • Use a typed slice copy for disjoint, all-valid fixed lists of at least 16 rows; preserve the original loop for small, nullable or overlapping inputs.
  • Reserve the non-inline payload once for fresh, unmasked varbinary and legacy varchar lists of at least 16 rows; keep the existing admission, allocation accounting and rollback.
  • Count borrowed Arrow validity ranges using masked boundary bytes and 64-bit population counts, and reuse the same algorithm for borrowed windows.
  • Resolve const/flat mapping once in fixed and byte row getters, retaining the existing slice conversion and returned byte aliases.

Performance

Apple M1, Go 1.27.1, GOMAXPROCS=1; ABBA order with six 250 ms samples per variant/case. Representative 2048-row/bit API results:

Optimization Baseline ns/op Optimized ns/op Speedup
Fixed int64 append, no NULL, retained capacity 1373 238.45 5.76×
Fresh varbinary append, 64-byte values 175504 68542.5 2.56×
Borrowed validity range count, mixed NULL 1917 48.335 39.66×
Typed int64 read, flat 8134.5 5593.5 1.45×

Append measurements compare main a53390c with 44e4b67; range/read measurements compare 44e4b67 with 56c4323. These are independent API workloads, not SQL throughput. Bytes-read benchmarks consume length and the first byte rather than all content.

Performance follow-up (2026-10-15)

A focused a53390c-to-ef9ba664d8 ABBA check (11 cases, six samples per variant/case) exposed an unmeasured downside: fresh, all-inline 8-byte varbinary batches of 2048 rows take 24843.5 -> 26402.5 ns/op (+6.28%); 128 rows are +4.73%. All-inline varchar cold cases are +1.80% to +2.49%. The pregrow path scans lengths even when there is no non-inline payload to reserve. The task owner has chosen to retain the current implementation and accept this measured local tradeoff; no additional code change is planned for it. The measurements remain disclosed for review. These are local API results; passing CI is not proof of no performance regression.

The original three small varchar cases with >5% median slowdown did not reproduce that magnitude in this focused check (-1.92%, -0.82%, +0.49%). The 2048-row 64-byte positive controls remain faster (varbinary 2.61x, varchar 1.80x). No production code changed in this follow-up.

Validation

  • Complete nulls/vector/batch/aggexec/group unit tests and complete nulls/vector race tests pass; the four optimization sources are unchanged by the CI repairs.
  • Typed-read tests pass with the typecheck tag, including mismatched-type rejection. Boundary tests cover NULLs, metadata, overlap/growth, short-mask panic, error precedence, allocation rollback, borrowed lifetime, getter bounds/aliases and serialization equality/round-trips.
  • The restart test passes focused, complete isolated-package coverage and focused adaptive race validation, with all SQL assertions and the original timeout value retained.
  • The new SQL-task publication regression fails with the original direct field read and passes with the locked getter, including 100 focused race repetitions. Complete frontend normal/race tests and the original CI-named two-CN lifecycle test pass on the combined patch.
  • Append tests and benchmark fixtures now release vectors/pools/accounts on early failures and check both on-heap and off-heap ownership. Identical injected-Fatal probes retain 256/3072 bytes before and zero after; their nonzero exits are intentional diagnostics. Focused append tests, complete vector normal/race tests and benchmark smoke checks pass after this test-only cleanup. The production optimization code is unchanged.
  • gofmt, git diff --check and incremental golangci-lint 2.14.0 pass (0 issues).

CI regression fixes

A cluster restart can wait in admission longer than the previous generation's SQL context budget. The restart test now cancels that context and creates a fresh context after each successful start, retaining the same three-minute budget and persistence/error/ID assertions.

During CN startup, SHOW TASKS may read ParameterUnit.TaskService while createTaskService publishes it under a lock. The frontend now calls the existing GetTaskService getter, pairing the read lock with SetTaskService. The not-ready error and returned service identity remain unchanged. A lightweight regression covers readiness before publication, a concurrent read, and the published service after joining the publisher. The CI-named TestIssue27719DropAccountCleansSQLTaskLifecycle remains intact.

Hosted CI run 38692131676 completed successfully for commit 6f4660d: Ubuntu unit tests, Linux arm64 SCA, both selected BVT jobs, UT coverage, coverage aggregation and CI Required all passed. Connector/J E2E and Iceberg module tidy also passed. Upgrade and other unselected jobs were skipped; cross-version upgrade and SQL throughput are not claimed.

CI test cleanup and current validation

The Ready-triggered run38847040729 failed two tests at unchanged head7b56098. All four published-view query assertions passed; account teardown then exhausted the20s cleanup context shared with publication teardown. Separately, a100ms global procfs snapshot exhausted its budget before locating the owned child, so the pipe-holder signal-evidence assertion failed although emergency cleanup found that child. Both test files were identical at verifiedbaseb678; these failures are not attributed to the container algorithms.

  • Register each publication/account cleanup after successful acquisition and retain reverse teardown order. Each resource receives its own existing20s context, cancelled promptly. The two-resource total cleanup bound is40s rather than one shared20s budget; the body2min limit,20s per operation and all SQL/error assertions are unchanged.
  • Capture signal metadata for an already-identified owned process before emergency kill, limited to32 observations and4KiB/status read. Recheck ownership and process generation before exposing metadata. Keep the global100ms snapshot,1s drain bound,neighbor/stale-PID checks and signal assertion. No additional production path or new process registry.
  • Merge mainb24d1b31155 to resolve the cleanup-helper conflict, preserving upstream failure diagnostics and the tested targeted observation helper. The original container algorithms and authorized frontend getter are unchanged by this resolution.

Local evidence: exactCrossDatabaseCorrelation root passed race before the merge(17.960s) and after the merge(14.360s,21 selected cases; package20.178s). The latter used the repository CGo wrapper with DWARF disabled(-w) to fit available local disk; source,race instrumentation,native link inputs and assertions are unchanged. Standard-debug linking was blocked by no space left on device and is not reported as passed. A controlled extracted-source fake-proc probe plus17 focused race repeats validates evidence after a truncated snapshot,stale-generation/neighbor rejection and missing-status handling. A separate context-lifecycle control validates independent20s resource budgets and prompt cancellation. Merged Linux/amd64 optools compilation and incremental vet/lint pass. Two same-process repeats of the exact merged SQL root also pass with race (42 selected test events), following the existing30s adaptive validation budget. Local Docker endpoints remain unavailable; the current-head hosted Ubuntu unit-test job has now completed successfully. This does not rewrite the local compile-only qualification.

Complete pre-merge macOS optools normal/race runs each had322 named PASS and two Linux-only SKIP, plus the same unrelated default-prebuild fixture failure. Exact-parent normal/race controls reproduce that failure; the merged focused control still fails. All failing logs are retained, and whole-package local green is not claimed. No third unrelated test fix is included. The final new-head CI and any subsequent required review remain authoritative; prior successful runs do not substitute for them.

Current-head CI result (2026-10-16)

MatrixOne ALL CI 38857209498 completed successfully for exact head ed3d69e09a76f679151af2b6c8c1c0fe406a5503 at 07:59:37 UTC. Ubuntu unit tests, arm64 SCA, shared build, both selected BVT jobs, UT coverage, coverage aggregation and CI Required passed. Connector/J and Iceberg module tidy also passed. Skipped upgrade checks are not cross-version validation. GitHub retains an Approved review for older commit7b56098; this is not claimed as a fresh review of the subsequent test repairs. The PR remains Ready and open for follow-up review.

@Lundomn Lundomn changed the title Optimize bulk vector appends for fixed and raw varlen values Optimize vector appends, borrowed validity ranges and typed reads Oct 14, 2026
@matrix-meow matrix-meow added size/XL Denotes a PR that changes [1000, 1999] lines and removed size/L Denotes a PR that changes [500,999] lines labels Oct 14, 2026
@Lundomn Lundomn changed the title Optimize vector appends, borrowed validity ranges and typed reads perf(container): optimize appends, validity ranges and typed reads Oct 14, 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 Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 7b56098abc2a493be906dc5e5e114c0c6c8801b3

Review completed. Read the assessment.

@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: 7b56098abc2a493be906dc5e5e114c0c6c8801b3

Assessment: approve

Reviewed the complete 13-file delta and affected callers. The design reuses existing allocation, rollback, conversion and synchronization owners while preserving aliasing, NULL, metadata and lifetime contracts. Tests cover meaningful boundaries and failure paths. Measured gains justify the added guards; the disclosed inline-batch slowdown remains a reasonable tradeoff. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • Verified the frozen head, merge base, complete patch and unchanged checkout. Recorded six behavioral closures in review-map.json.

  • Preflight passed. Built native prerequisites through the repository build owner; independently verified 192 source inputs and retained artifact hashes.

  • All 16 added container tests passed with -tags=typecheck and the supplied test-exec, including overlap, rollback, validity boundaries, borrowed lifetime and getter guards. Receipt: checks/1792121115407814013-5.json; log: container-focused.log.

  • Exact-base/head ABBA benchmarks used identical fixtures and six samples per variant. Representative speedups: fixed append 4.92x, non-inline byte append 2.02x, validity count 37.92x, typed read 1.49x. Follow-up confirmed 2.07x non-inline gains; small batches were 2.7% slower and inline batches 3.0% slower, versus 6.7% inline slowdown initially.

  • Reused the supplied exact-head successful Ubuntu UT, arm64 SCA, UT coverage and selected BVT conclusions. Inspected task-service publication and restart-context ownership independently.

  • Reconciled 12 successful execution receipts with commands, source fingerprints and retained logs. Final audit passed: checks/1792121730664720617-4.json. Evidence resides under /home/xupeng/.local/state/mo-bot/jobs/3aeae1b5530625986774ecb3/attempt-1/validation-audit.json and final-evidence-index.json.

Limitations:

  • Raw CI and historical author logs were not supplied; frontend and restart tests were not rerun locally. Historical author measurements were not treated as independently verified results.

  • Local measurements are single-host API microbenchmarks, not SQL throughput or cross-platform guarantees. Inline prescanning has a measured workload-dependent cost.

  • Linked issue bodies were not separately supplied; their scoped contracts were assessed through the frozen PR description and source.

  • An initial diagnostic audit rejected a final-newline difference in the retained patch. Content equivalence was subsequently verified; this was not a product-test failure.

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

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 03:45 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-10-16 05:06 UTC · at 7b56098abc2a493be906dc5e5e114c0c6c8801b3

This pull request spent 1 hour 20 minutes 55 seconds in the queue, with no time running CI.

Reason

The merge conditions cannot be satisfied due to failing checks

  • Mergify Merge Protections
  • CI Required

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 08:00 UTC · Rule: main · triggered by @Lundomn with the merge queue checkbox
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-16 08:38 UTC · at a5b36161b6f4f8e710bb313a6be3c545538fce92

This pull request spent 38 minutes 34 seconds in the queue, with no time running CI.

Reason

Pull request #30160 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

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

Labels

dequeued kind/enhancement kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance]: Reduce column-container append, validity-range and typed-read overhead

4 participants