Skip to content

perf(objectio): compress directly into available writer arena - #32774

Merged
XuPeng-SH merged 6 commits into
mainfrom
codex/32751-direct-arena-compress-main-20261115
Nov 16, 2026
Merged

XuPeng-SH merged 6 commits into
mainfrom
codex/32751-direct-arena-compress-main-20261115

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 15, 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:

Related to #32751

What this PR does / why we need it:

The object writer currently compresses into a separate scratch buffer and then copies the compressed bytes into the writer arena. When the unused arena tail already fits the LZ4 compression bound, that creates an avoidable live allocation and copy.

Compress directly into the unused tail when it is large enough and does not overlap the input. Commit only the actual compressed length to the arena after success. Inputs overlapping the tail, insufficient space, and writers without an arena keep the existing scratch path. The LZ4 format, extent metadata, ownership of completed output, and arena accounting remain unchanged.

Validation on a CPU-only 57 host:

  • Exact compressed bytes, offsets, NULLs, multiple sequential writes, alias and insufficient-capacity fallback, and an in-memory object write/read after arena reuse were checked. The full objectio package passed normally and under race; the independent concurrent-arena test passed 100 race repetitions. Incremental lint and formatting passed.
  • In two isolated 1-CN LOAD/ALTER cases (one 8 MiB field and 31 64 KiB fields, large field first or last), all row hashes and strict/non-strict diagnostics matched. The load-idle native profile dropped the 16 MiB compression scratch while retaining the 32 MiB arena. Sampled LOAD RSS deltas changed 115.13→105.11 MiB and 106.39→95.11 MiB; one run per order with 5 ms sampling is not an exact peak or a production-scale estimate.
  • Combined with merged perf: avoid repeated TEXT assignment buffer growth #32771, an additional 1-CN case preserved all hashes and diagnostics. Its sampled LOAD/ALTER RSS deltas were 96.68/34.46 MiB versus 115.13/50.46 MiB in the separate base run; profile attribution confirms both allocation reductions, but individual runs are not directly additive.
  • Three alternating microbenchmark rounds showed little change for 64 B–4 KiB serial inputs and about 52% lower time for 8 MiB varied input in the direct path. A four-producer 4 KiB case was 1.3% slower. The initial 8 MiB fallback samples were 4–6% slower; eight additional alternating pairs had a +0.39% median with several-percent variation. These shared-host samples do not prove a universal no-regression result.

Rows whose compression bound exceeds the unused arena capacity retain the existing path; this alone does not resolve the original very-large-row OOM.

Overlap guard and SCA follow-up

  • unsafe is confined to compression_overlap.go, which compares addresses without dereferencing or reconstructing pointers. The caller must keep both buffers and their owners valid and must not release the arena concurrently. writer.go remains subject to the unsafe-import check. Empty, same-start, containment, both partial-overlap directions, adjacent and separate slices are tested; real compression tests verify that overlapping input falls back and adjacent input uses the direct path.
  • The pinned molint is the official master commit 147a3f213653 merged in linter PR 57; it no longer depends on the unmerged compatibility branch. Compared with the previous MatrixOne main pin, this version also includes three function-scoped recover approvals already merged in linter PR 56.
  • The complete pkg/objectio suite passed normally and under race on the earlier PR head. After merging the latest main including perf(fileservice): avoid buffering S3 uploads for disk cache #32782, compression and S3 writer/cache interaction tests passed under race, and the official merged molint plus golangci passed make static-check-selected STATIC_CHECK_PACKAGES=./pkg/objectio on commit 11e75981aa3ce38812484cb533c093be89bf9260. Full CI is running on that head. The linter itself passed go test ./... before merge.
  • Comparing the guard extraction against the earlier PR head on the shared 57 host, the first three-pair 64-byte sample had a +3.35% median; six additional alternating pairs had a -0.23% paired median. The 4 KiB follow-up paired median was +0.09%. These short samples are noisy and do not establish a universal performance result.

@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 Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · superseded

Commit: 4063c5c823217927747b6703c54c5d1b2416d6fe

"interrupted"

@XuPeng-SH

XuPeng-SH commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 3ad1e360abb59f81985652a86510251bb3d574f6

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 3ad1e360abb59f81985652a86510251bb3d574f6

Assessment: approve

Direct compression reuses the existing arena owner and accounting. Full-bound and overlap guards preserve encoding and required fallbacks. The small fast path adds justified complexity to avoid compression scratch allocation and copying.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Full pkg/objectio normal and race suites passed on this head with Go 1.27.1: 190 top-level tests in each, including all five new cases.

  • The independent-arena concurrency test passed 100 focused race repetitions.

  • go vet, changed-file gofmt and complete-delta whitespace checks passed.

  • Preflight and native prerequisite verification passed. validation-audit.json reconciles nine current check receipts with retained logs; all four discussion entries are accounted for and source is unchanged.

Limitations:

  • Author SQL/RSS and benchmark results were not independently reproduced; raw logs were unavailable. This assessment does not establish umbrella issue #32751 acceptance or production OOM resolution.

  • Hosted UT, SCA, coverage, E2E and Go-analysis checks remained pending in the frozen snapshot.

@XuPeng-SH
XuPeng-SH marked this pull request as ready for review November 15, 2026 23:17
@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 Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · superseded

Commit: ebb826644f3528f71819ce9a357cfb34c81a56f9

"interrupted"

@XuPeng-SH

XuPeng-SH commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 11e75981aa3ce38812484cb533c093be89bf9260

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

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: 11e75981aa3ce38812484cb533c093be89bf9260

Assessment: approve

Approve the scoped compression optimization. The full-bound fit and overflow-safe overlap guard reuse the existing arena, codec, allocation accounting and scratch fallback without adding state or changing object format. The small private helper and exact file-specific linter permission are proportionate to accepting arbitrary borrowed input. Current S3/cache and retry consumers preserve output lifetime, and the official pin's complete policy delta and negative controls were reviewed. Prior approvals remain consistent with the current source; no actionable finding or unmet required contract remains.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Current full objectio package passed normally and under race detection: 198 root tests/seed runs in each mode, no skips. This includes all seven added compression roots and public writer/S3FS cache readback after arena release plus retry-policy preservation. See objectio-normal.jsonl, objectio-race.jsonl and their receipts in validation-audit.json.

  • The independent-arena concurrency root passed 100 race repetitions, selected from its measured 0.01s race duration. See race-stress-plan.json and arena-stress-race.jsonl.

  • Official make static-check-selected passed for ./pkg/objectio with pinned standalone molint 147a3f213653 and checksum-verified golangci-lint v2.14.0, using the repository configuration. Changed files passed gofmt and git diff --check; source remained unchanged.

  • Exact old/new linter module identities and the complete six-file policy diff were retained. Both affected analyzer packages passed three test roots with positive and negative fixtures; tested input hashes were rechecked. See linter-modules.json, linter-pin.patch and linter-policy-tests.jsonl.

  • Preflight passed; reused native prerequisites matched 195 current inputs, 69 artifact hashes and compiler identity. Claimed checks were matched to command/source/exit receipts and retained logs, with module identity binding the upstream analyzer tests. All ten discussion keys are accounted for exactly once.

Limitations:

  • No new whole-SQL, RSS, GPU or benchmark campaign was run. Author performance reports are context without matching raw execution artifacts; no full-OOM or universal latency conclusion is claimed.

  • The S3FS integration test uses its disk-backed object-storage endpoint, not a live cloud service. Static analysis was selected for the owning package rather than the whole repository.

  • The supplied #57/#58 linked-issue records do not provide the external linter discussion. The exact official pinned module, policy diff and negative fixtures establish the material permission scope. An unavailable old tool cache was recovered by provisioning the pinned tools in this member's cache.

@XuPeng-SH
XuPeng-SH merged commit 4349e73 into main Nov 16, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/32751-direct-arena-compress-main-20261115 branch November 16, 2026 02:02
XuPeng-SH added a commit that referenced this pull request Nov 16, 2026
## What type of PR is this?

- [x] Improvement

## Which issue(s) this PR fixes:

Related to #32751; 4.2-dev counterpart of #32774.

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

When an arena has enough unused capacity for the LZ4 compression bound,
compress independently owned writer buffers directly into its tail and
commit only the actual output length. This avoids the separate
compression scratch buffer and the subsequent copy on those writes. The
existing scratch path remains in use when the bound does not fit or no
arena is available.

The internal serialization and metadata buffers are created
independently of the arena and marked with a private ownership type.
`WriteWithCompress`, which accepts arbitrary borrowed bytes, always
keeps the original scratch path even when the bytes happen not to
overlap. Thus existing external callers retain their previous behavior,
while the in-tree serialization and metadata paths can use direct
compression. The object format, extent and arena accounting, SQL
behavior, and 4.2 pool limits are unchanged.

No `unsafe` import, new linter exception, or linter pin change is needed
on 4.2. This PR no longer depends on the unmerged linter compatibility
branch in linter #58. The main implementation and its reviewed narrow
exception are tracked separately in #32774 and linter #57.

## Validation

On CPU-only 57, Go 1.26.4, final commit `93e4450817` rebased onto
`25305b6137`:

- The complete `pkg/objectio` suite passed normally and under race. This
includes the new direct-compression, overlapping/adjacent borrowed
inputs, empty and incompressible input, no-arena and insufficient-tail
fallbacks, arena reuse, multicolumn readback, and the new base's
S3-cache interaction tests. For these runs the existing hardcoded test
directory was temporarily redirected into the task-owned test directory
and restored afterwards.
- The independent concurrent-arena test also passed 100 race repetitions
before the final rebase; the full race run passed again on the final
base.
- Official merged `molint check -mod=readonly ./pkg/objectio` passed;
the existing selected golangci checks passed. A separate negative
control verified that the official checker fails on an injected
unapproved `unsafe` import.
- A 1-CN LOAD/ALTER run with one 8 MiB field and 31 64 KiB fields
verified all 32 complete payload hashes after each operation. The test
services exited and their isolated data was removed.
- Four alternating shared-host benchmark pairs showed similar
small-input and 4-producer allocations and timings to the previous
overlap-guard implementation. A further eight alternating 8 MiB pairs
had a +2.38% median latency difference, with individual pairs from
-12.34% to +8.82%; this noisy sample does not establish a stable
regression or improvement. Both versions measured 16 B/op and 1 alloc/op
in that direct-path benchmark. Earlier comparisons of the overlap-guard
version against the original scratch baseline showed a benefit for the 8
MiB direct path; those earlier measurements are not a direct measurement
of this final commit.

The 4.2-dev `go vet -vettool` SCA step has a pre-existing limitation: it
can print linter diagnostics while returning success. This was
reproduced with a negative control and observed in a previous green CI
run. This PR does not change that branch-wide CI behavior, so the
standalone official `molint check` above is independent evidence for the
modified package; a green legacy SCA job alone is not proof that its
linter findings were enforced.

Large rows whose compression bound cannot fit in the remaining arena
still use the existing scratch path; this optimization alone does not
resolve the original very-large-row OOM.

This branch was previously deployed

1 inactive deployment
ci — 11e75981 Deployed Nov 16, 2026 by XuPeng-SH
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.

2 participants