Repository navigation
[4.2-dev] perf: backport mpool teardown and read filter allocation fixes - #29292
Conversation
- [ ] 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 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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
What type of PR is this?
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-devat7a68d42c4ec151f9af5890ee56b4d24afd87b843, preserving original authors andcherry-pick -xprovenance:6ad98a5f5e8cbfd8f328836676f2186bfa2e09c7): replace the multi-termReadFilterSearchint64-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.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 publicOnHeapOutstanding()behavior are unchanged. Include the correctness/concurrency tests and scale benchmark.Release-branch adaptations
math/bits; unrelated main-only imports/implementations are not brought over.pkg/tests/issues/issue_277xx_ddl_consistency_test.goadjustment bundled with perf(mpool): narrow on-heap teardown scans #28799: that test does not exist on4.2-dev. Keep all direct mpool regression coverage.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).mo-cgo-testwrapper, each with-race -count=100 -timeout=120s: PASS forTestOnHeapShardHintsAreConservativeAndExactandTestOnHeapShardHintsConcurrentPublicationAndCrossPoolFree. 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=readonlyandgo vet -mod=readonlyfor both owning packages withGOWORK=offand repository-local native include/library paths: PASS. Native prerequisites were built from this worktree's bundled thirdparty sources and CGo sources.git diff --checkandgofmt -lfor all four changed files: PASS.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.