Skip to content

[4.2-dev] perf: backport mpool teardown and read filter allocation fixes - #29292

Merged
XuPeng-SH merged 2 commits into
matrixorigin:4.2-devfrom
gouhongshen:codex/backport-4.2-gc-pressure
Sep 23, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:4.2-devfrom
gouhongshen:codex/backport-4.2-gc-pressure

Conversation

@gouhongshen

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:

References #28530 and #28609. Backports #28799 and #28610 to 4.2-dev.

The mpool change remains a scoped mitigation, not a claim that all costs in #28530 are eliminated.

What this PR does / why we need it:

Backports two already-merged main fixes onto 4.2-dev at 7a68d42c4ec151f9af5890ee56b4d24afd87b843, preserving original authors and cherry-pick -x provenance:

  1. fix(objectio): compact multi-term read filter marks #28610 (6ad98a5f5e8cbfd8f328836676f2186bfa2e09c7): replace the multi-term ReadFilterSearch int64-per-source-row marks with a compact bitset and allocate the result to its exact size. Preserve deduplication, ascending row order, and the existing single-term and malformed-input paths. Include the allocation regression test.
  2. perf(mpool): narrow on-heap teardown scans #28799 (14e457608003381ef409fbf0c475e0a931633a28): record conservative per-pool pointer-shard hints and restrict destroy-time on-heap ownership scans to those shards. Registry maps remain authoritative; free does not clear hints; noLock pools and public OnHeapOutstanding() behavior are unchanged. Include the correctness/concurrency tests and scale benchmark.

Release-branch adaptations

  • Resolve the objectio import conflict by adding only math/bits; unrelated main-only imports/implementations are not brought over.
  • Omit the unrelated pkg/tests/issues/issue_277xx_ddl_consistency_test.go adjustment bundled with perf(mpool): narrow on-heap teardown scans #28799: that test does not exist on 4.2-dev. Keep all direct mpool regression coverage.
  • Preserve the release branch's existing allocation-account/lease implementation. Accounted allocations are off-heap and do not require on-heap hints.

Only four files change. No catalog/schema migration, configuration, wire or on-disk format, dependencies, or CI workflow changes. No changes to release tags or running deployments.

Validation

Fresh local validation on Go 1.26.4, Darwin/arm64:

  • GOWORK=off go list -mod=readonly ./pkg/common/mpool ./pkg/objectio: PASS.
  • GOWORK=off go test -mod=readonly -count=1 -timeout=120s ./pkg/common/mpool: PASS.
  • GOWORK=off go test -mod=readonly -race -json -count=1 -timeout=240s ./pkg/common/mpool: PASS (full package).
  • Repository mo-cgo-test wrapper, each with -race -count=100 -timeout=120s: PASS for TestOnHeapShardHintsAreConservativeAndExact and TestOnHeapShardHintsConcurrentPublicationAndCrossPoolFree. Initial JSON durations were below timer resolution; the adaptive budget therefore used N=100.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=180s ./pkg/objectio: PASS (full package, including allocation and legacy predicate equivalence regressions; also a consumer of mpool).
  • go build -mod=readonly and go vet -mod=readonly for both owning packages with GOWORK=off and repository-local native include/library paths: PASS. Native prerequisites were built from this worktree's bundled thirdparty sources and CGo sources.
  • git diff --check and gofmt -l for all four changed files: PASS.
  • Self-review: exact ownership diagnostics, monotonic atomic hint publication, cross-pool frees, fixed-size hint storage, bitset bounds, result order and release-branch adaptations checked. No additional lifecycle, external wait or persistent state introduced.

Full distributed BVT, end-to-end QA profiling and new performance benchmarks were not run for this backport. CI remains required; no end-to-end latency improvement is claimed from these unit tests.

gouhongshen and others added 2 commits September 23, 2026 19:09
- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

Fixes matrixorigin#28609

`ReadFilterSearch` used one `int64` marker per source row when merging
multiple filter terms. For large object blocks this created substantial
allocation churn and GC CPU. This PR replaces the row marker array with
a compact bitset, preserves ascending row-order output, and allocates
the result slice to its exact match count. It also adds a regression
test that checks combined searches do not allocate a block-sized marker
array.

Tests:

- `go test ./pkg/objectio -count=1`

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 6ad98a5)
- [ ] API-change
- [ ] BUG
- [x] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

References matrixorigin#28530. This is a scoped mitigation and intentionally does
not close the issue: pools that touch many pointer shards still inspect
most of the registry, and the reported QA workload profile has not yet
been re-captured with this change.

`MPool.destroy()` previously called `OnHeapOutstanding()` for locking
pools, scanning and locking every process-wide pointer-registry shard
even when the pool had allocated only a few on-heap objects.

Each locking pool now records a conservative bitset of shards into which
successful on-heap pointer registrations were published. Teardown scans
only those shards and still derives exact outstanding bytes and object
counts from the authoritative pointer maps. Bits are monotonic and are
not cleared on free, so stale bits can only cause extra scans; they
cannot hide a still-live pointer. Off-heap registrations do not set the
hints, noLock pools retain their local exact-map path, and the public
`OnHeapOutstanding()` full-scan behavior is unchanged.

The hot path adds a bit-test on registration and a CAS only on first
publication to a shard. The pool stores two atomic words (16 bytes at
the current 128-shard configuration); it does not add per-allocation
heap objects or change pointer-map ownership.

Linux/amd64, Ryzen 9 7900X, `GOMAXPROCS=8`, 3 samples, 100ms each. Each
operation creates a target pool, allocates/frees the listed number of
on-heap objects, then deletes it while unrelated registry entries remain
live. Candidate medians:

| Unrelated live entries | Target owned objects | Hinted shards |
End-to-end pool lifecycle |
|---:|---:|---:|---:|
| 0 | 1 | 1 | 0.38 us/op |
| 10,000 | 1 | 1 | 0.90 us/op |
| 100,000 | 1 | 1 | 6.05 us/op |
| 100,000 | 8 | 8 | 44.2 us/op |
| 100,000 | 32 | 29 | 161.6 us/op |
| 100,000 | 128 | 80 | 464.5 us/op |

The benefit narrows as an owner touches more shards; the 128-object case
is close to a full scan. A prior paired one-object microbenchmark on the
same hint implementation measured about 5–8.5 us/op versus 501–737 us/op
at the base. These are local microbenchmarks, not end-to-end SQL or the
original QA workload. Please keep matrixorigin#28530 open until the same QA
workload/profile is re-measured and the residual high-fanout cost is
assessed.

- Focused UT: `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run
"^TestOnHeapShardHints" ./pkg/common/mpool`
- Owning package UT and race: `.agents/skills/mo-dev/scripts/mo-cgo-test
-count=1 ./pkg/common/mpool` and
`.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1
./pkg/common/mpool`
- New concurrency cases: run each exact test with `-race -count=100`.
- Scoped static checks: `golangci-lint run -c .golangci.yml
./pkg/common/mpool`, `go vet ./pkg/common/mpool`, and repository
`molint` on the package.
- Scale benchmark: `.agents/skills/mo-dev/scripts/mo-cgo-test -run "^$"
-bench "^BenchmarkMPoolDestroyUnrelatedPointersByOwnerSize$"
-benchtime=100ms -count=3 ./pkg/common/mpool`.

BVT is not applicable: this changes internal allocator diagnostics only;
SQL-visible results and ownership/free semantics are unchanged.

(cherry picked from commit 14e4576)
@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 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.

GPT-6 High deep review at exact head 710737a against 4.2-dev base 7a68d42: APPROVE. Reviewed all four changed files, the source backports and release-branch adaptations. The mpool shard-hint teardown preserves authoritative registries and conservative cross-pool ownership; the ObjectIO compact read-filter path preserves predicate results/order while tightening allocation. Added concurrency, teardown, and equivalence regressions align with the changed contracts. Exact-head required CI is green, including UT, SCA, coverage, and multi-CN BVTs. No remaining blocking findings.

This branch was previously deployed

1 inactive deployment
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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants