Skip to content

perf(compile): reduce GC pressure in ConvertOperatorToPhyOperator - #24279

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
aunjgr:perf/reduce-gc-phyoperator
May 6, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
aunjgr:perf/reduce-gc-phyoperator

Conversation

@aunjgr

@aunjgr aunjgr commented May 6, 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 #21116

What this PR does / why we need it:

Arena-allocate all PhyOperator nodes and child-pointer slices from two pre-sized slices instead of individual heap allocations per operator. This reduces GC pressure in ConvertOperatorToPhyOperator which runs post-execution for every statement that needs EXPLAIN ANALYZE output.

Changes

  • Introduce phyOpArena struct holding a single []PhyOperator node slice and a single []*PhyOperator child-pointer slice, both pre-allocated to exact capacity via countOperators.
  • All nodes are appended into the arena; child pointer slices are sub-sliced from the shared buffer. For a 50-operator query, this reduces ~150 heap allocations to ~4.
  • getDestReceiver now returns nil for the common case (non-Connector/non-Dispatch operators) instead of allocating an empty slice every time.
  • Cache op.GetOperatorBase() in a local variable to avoid repeated interface dispatch.

Impact

  • For prepared statements: zero regression — the PhyOperator tree is built once and reused via UpdatePreparePhyOperator which does in-place pointer updates with no allocations.
  • For ad-hoc statements: one countOperators tree walk added (cheap pointer chase over hot cache lines), but eliminates N-1 make calls and N new-equivalent allocations.
  • JSON serialization format unchanged — Children []*PhyOperator still serializes as a nested tree.

Test plan

  • Existing unit tests pass (pkg/sql/models/...)
  • CI BVT (no behavioral change, only allocation strategy)

🤖 Generated with Claude Code

Arena-allocate all PhyOperator nodes and child-pointer slices from two
pre-sized slices instead of individual heap allocations per operator.
For a 50-operator query this reduces ~150 allocations to ~4.

Also avoid allocating an empty receiver slice for operators that are
not Connector or Dispatch (the vast majority).

Fixes matrixorigin#21116

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@aunjgr
aunjgr requested a review from ouyuanning as a code owner May 6, 2026 05:09
@qodo-code-review

Copy link
Copy Markdown
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@mergify mergify Bot added the queued label May 6, 2026
@mergify

mergify Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-05-06 07:15 UTC · Rule: main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-05-06 08:14 UTC · at c1f1f136f894dccaaa14fa50b43af76daf8abd18 · squash

This pull request spent 59 minutes 32 seconds in the queue, including 59 minutes 16 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage

@mergify
mergify Bot merged commit 281a057 into matrixorigin:main May 6, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label May 6, 2026
@aunjgr
aunjgr deleted the perf/reduce-gc-phyoperator branch May 6, 2026 15:07
fengttt pushed a commit to fengttt/matrixone that referenced this pull request May 7, 2026
…trixorigin#24279)

Arena-allocate all `PhyOperator` nodes and child-pointer slices from two pre-sized slices instead of individual heap allocations per operator. This reduces GC pressure in `ConvertOperatorToPhyOperator` which runs post-execution for every statement that needs EXPLAIN ANALYZE output.

### Changes

- Introduce `phyOpArena` struct holding a single `[]PhyOperator` node slice and a single `[]*PhyOperator` child-pointer slice, both pre-allocated to exact capacity via `countOperators`.
- All nodes are appended into the arena; child pointer slices are sub-sliced from the shared buffer. For a 50-operator query, this reduces ~150 heap allocations to ~4.
- `getDestReceiver` now returns `nil` for the common case (non-Connector/non-Dispatch operators) instead of allocating an empty slice every time.
- Cache `op.GetOperatorBase()` in a local variable to avoid repeated interface dispatch.

### Impact

- For prepared statements: zero regression — the PhyOperator tree is built once and reused via `UpdatePreparePhyOperator` which does in-place pointer updates with no allocations.
- For ad-hoc statements: one `countOperators` tree walk added (cheap pointer chase over hot cache lines), but eliminates N-1 `make` calls and N `new`-equivalent allocations.
- JSON serialization format unchanged — `Children []*PhyOperator` still serializes as a nested tree.

Approved by: @ouyuanning
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…trixorigin#24279)

Arena-allocate all `PhyOperator` nodes and child-pointer slices from two pre-sized slices instead of individual heap allocations per operator. This reduces GC pressure in `ConvertOperatorToPhyOperator` which runs post-execution for every statement that needs EXPLAIN ANALYZE output.

### Changes

- Introduce `phyOpArena` struct holding a single `[]PhyOperator` node slice and a single `[]*PhyOperator` child-pointer slice, both pre-allocated to exact capacity via `countOperators`.
- All nodes are appended into the arena; child pointer slices are sub-sliced from the shared buffer. For a 50-operator query, this reduces ~150 heap allocations to ~4.
- `getDestReceiver` now returns `nil` for the common case (non-Connector/non-Dispatch operators) instead of allocating an empty slice every time.
- Cache `op.GetOperatorBase()` in a local variable to avoid repeated interface dispatch.

### Impact

- For prepared statements: zero regression — the PhyOperator tree is built once and reused via `UpdatePreparePhyOperator` which does in-place pointer updates with no allocations.
- For ad-hoc statements: one `countOperators` tree walk added (cheap pointer chase over hot cache lines), but eliminates N-1 `make` calls and N `new`-equivalent allocations.
- JSON serialization format unchanged — `Children []*PhyOperator` still serializes as a nested tree.

Approved by: @ouyuanning
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…trixorigin#24279)

Arena-allocate all `PhyOperator` nodes and child-pointer slices from two pre-sized slices instead of individual heap allocations per operator. This reduces GC pressure in `ConvertOperatorToPhyOperator` which runs post-execution for every statement that needs EXPLAIN ANALYZE output.

### Changes

- Introduce `phyOpArena` struct holding a single `[]PhyOperator` node slice and a single `[]*PhyOperator` child-pointer slice, both pre-allocated to exact capacity via `countOperators`.
- All nodes are appended into the arena; child pointer slices are sub-sliced from the shared buffer. For a 50-operator query, this reduces ~150 heap allocations to ~4.
- `getDestReceiver` now returns `nil` for the common case (non-Connector/non-Dispatch operators) instead of allocating an empty slice every time.
- Cache `op.GetOperatorBase()` in a local variable to avoid repeated interface dispatch.

### Impact

- For prepared statements: zero regression — the PhyOperator tree is built once and reused via `UpdatePreparePhyOperator` which does in-place pointer updates with no allocations.
- For ad-hoc statements: one `countOperators` tree walk added (cheap pointer chase over hot cache lines), but eliminates N-1 `make` calls and N `new`-equivalent allocations.
- JSON serialization format unchanged — `Children []*PhyOperator` still serializes as a nested tree.

Approved by: @ouyuanning
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…trixorigin#24279)

Arena-allocate all `PhyOperator` nodes and child-pointer slices from two pre-sized slices instead of individual heap allocations per operator. This reduces GC pressure in `ConvertOperatorToPhyOperator` which runs post-execution for every statement that needs EXPLAIN ANALYZE output.

### Changes

- Introduce `phyOpArena` struct holding a single `[]PhyOperator` node slice and a single `[]*PhyOperator` child-pointer slice, both pre-allocated to exact capacity via `countOperators`.
- All nodes are appended into the arena; child pointer slices are sub-sliced from the shared buffer. For a 50-operator query, this reduces ~150 heap allocations to ~4.
- `getDestReceiver` now returns `nil` for the common case (non-Connector/non-Dispatch operators) instead of allocating an empty slice every time.
- Cache `op.GetOperatorBase()` in a local variable to avoid repeated interface dispatch.

### Impact

- For prepared statements: zero regression — the PhyOperator tree is built once and reused via `UpdatePreparePhyOperator` which does in-place pointer updates with no allocations.
- For ad-hoc statements: one `countOperators` tree walk added (cheap pointer chase over hot cache lines), but eliminates N-1 `make` calls and N `new`-equivalent allocations.
- JSON serialization format unchanged — `Children []*PhyOperator` still serializes as a nested tree.

Approved by: @ouyuanning

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/enhancement kind/refactor Code refactor size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactoring]: Reduce the number of objects in ConvertOperatorToPhyOperator

3 participants