Skip to content

fix(fulltext2): avoid boxing loaded UUID membership probes - #28955

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-27800-loaded-uuid-20260916
Sep 17, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-27800-loaded-uuid-20260916

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #27800

What this PR does / why we need it:

Changes:

  • Read loaded FULLTEXT2 UUID primary-key content with pkContent and parse directly from bytes with the existing google/uuid parser.
  • Probe the runtime filter with query-owned raw UUID storage and a pointer-free per-owner backing object, avoiding loaded-path boxing and re-encoding after warm-up.
  • Return false for invalid loaded ordinals, docmap spans, truncated payloads, or malformed UUID rows before any typed assertion; keep build-side typed fallback unchanged.
  • Extend loaded UUID representation, malformed-row, liveness/score, stream, ownership, race, and benchmark coverage.

Non-goals:

  • No raw-16 docmap format change, migration, wire/protocol change, CDC behavior change, or P1 persistence work.
  • SQL LIMIT cases verify deterministic pagination; they do not claim unsupported pushed top-k eligibility.

Validation and real-Bloom benchmark

  • Base: 5bf6d24157959febb839615462c30eafb5046fc9; tested product head: 69e7589f3bbb169ba004d8f5f0e6273df4a2f5ea.
  • mo-55, Go 1.26.6, task-private matching native libraries. Additional test-only fixtures/benchmarks were applied locally to this head; they are not included in the PR.
  • Real Builder -> Serialize -> Deserialize loaded UUID segment and UUID runtime-vector Bloom: typed, pointer-backed and local-copy results agree, with no false negatives for inserted UUIDs. Focused normal/race tests, full FULLTEXT2/docfilter package tests, owning-package build/vet and formatting checks passed.
  • The tested inline-field variant was rejected by the real CGo call (Go pointer to unpinned Go pointer). The independent pointer-free backing object and local-copy variants passed ordinary CGo checks. cgocheck2 remains blocked before tests by sonic/loader.casModule initialization; this is not a safety PASS under that instrumentation.

Fresh-wrapper lifecycle benchmark, including first allocation; real Bloom and loaded segment shared outside timing. Mixed-probe medians below use GOMAXPROCS=1, 10 repetitions, 2s per benchmark; values are per lifecycle:

Probes Original typed Pointer-backed Local 16-byte copy
1 173.6 ns; 104 B; 4 allocs 142.6 ns; 80 B; 2 allocs 151.3 ns; 40 B; 2 allocs
16 2.481 us; 1,304 B; 49 allocs 1.599 us; 80 B; 2 allocs 1.589 us; 280 B; 17 allocs
256 37.8 us; 20,504 B; 769 allocs 19.9 us; 80 B; 2 allocs 24.6 us; 4,120 B; 257 allocs
4096 609.4 us; 327,704 B; 12,289 allocs 317.5 us; 80 B; 2 allocs 384.6 us; 65,560 B; 4,097 allocs

The measured property is steady-state probe allocation avoidance: each wrapper allocates its 16-byte backing storage on first use and reuses it thereafter; this does not mean the entire query or membership lifecycle is allocation-free. The legal local copy escapes through the real CGo probe and allocates per probe. Single-probe local copy uses less memory; at 16 probes the measured times are essentially tied. At 256/4096 probes the pointer-backed medians are about 17–19% lower than local copy and 47–48% lower than typed. GOMAXPROCS=10 and a separate 10-worker benchmark show the same allocation pattern. Direct byte parsing alone measures 0 B/0 allocs versus typed boxing at 64 B/2 allocs.

Independent CPU and allocation/heap profiles support the allocation mechanism: typed decoding/boxing and local-copy per-probe allocation are removed from the steady-state pointer-backed path. CPU profiles were collected separately from allocation instrumentation.

Evidence: mo-55 /home/sunyuze/fulltext2-uuid-28955-20260916T084629Z/artifacts/ contains raw 10-run logs, median-summary.tsv, profiles, test exit codes, resource samples and source/native/binary hashes. Test binary SHA256: 8591ce22c550753a1cfd1be8227e80ac2e73e3022ca5262fe453c452bd46e681.

Limitations: timing is INCONCLUSIVE_HOST_BUSY because shared-host load and swap activity varied. Numbers are descriptive micro medians, not statistically established speedups or SQL throughput claims. benchstat installation was blocked by a network timeout; all ten runs were retained and median summaries used. No 2.3M SQL matrix was run.

CI and QA

  • The canonical membership BVT expected output includes corrected result delimiters; local micro tests do not replace SQL BVT acceptance.
  • QA required: yes, for the production FULLTEXT2 membership path. CI/BVT and deployment acceptance remain separate from the local results above.
  • In the pre-rebase run 35194357473 (generation 35194357473-1, head 34b82646abb48e24d8bafe97f628fcc1e1ea8970), Build, SCA, Proxy BVT and pessimistic multi-CN BVT completed successfully. The UT Coverage producer exited with code 1 after the shared pkg/tests/issues/isolated suite reported TestAutoIDCacheRestartAndDisabledNode and package-level failure; it published diagnostic artifacts 10486052461 and 10486240757. The downstream Coverage job then reported prerequisites_ready=false and did not calculate a coverage verdict. This is a producer test-run failure, not a changed-code coverage threshold verdict. The regular Ubuntu UT job also failed in unrelated pkg/vm/engine/tae/db/test/Test_CheckpointChaos2 with a checkpoint context deadline and expected/actual list mismatch; none of the PR-touched FULLTEXT2 files are involved.
  • fengttt approved the pre-rebase head on 2026-09-16; the rebase requires a fresh review decision. The measurements above supplement the requested comparison. A fresh exact-head CI run after rebasing onto 5bf6d24157959febb839615462c30eafb5046fc9 is required; the pre-rebase run is retained as diagnostic evidence only.

@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 →

f docfilter.MembershipFilter
scratch [8]byte // reused encode buffer for the hot integer-PK path (Test copies out)
uuidScratch [16]byte // query-owned raw UUID probe before the CGo-safe copy
uuidProbe *[16]byte // pointer-free backing object passed to CGo filters

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.

Is this really an optimization? Why use a pointer? Why not just keep a copy of 16 bytes? It is highly unlikely that holding a pointer is any cheaper than 16 bytes.

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.

Oh well, seems you are saying this is exactly the purpose of this PR. So my question, do you have a benchmark or profiling that support this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in exact head 3f6b8d2. Added a deterministic pointer-backed versus inline-copy benchmark covering hit, miss and mixed probes, and corrected the canonical membership result delimiters. Local benchmark execution is BLOCKED_ENVIRONMENT because existing docfilter CGo symbols are unavailable; no performance PASS is claimed. Please re-review this head.

f docfilter.MembershipFilter
scratch [8]byte // reused encode buffer for the hot integer-PK path (Test copies out)
uuidScratch [16]byte // query-owned raw UUID probe before the CGo-safe copy
uuidProbe *[16]byte // pointer-free backing object passed to CGo filters

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.

Oh well, seems you are saying this is exactly the purpose of this PR. So my question, do you have a benchmark or profiling that support this?

@fengttt fengttt 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.

See comments. @VioletQwQ-0

@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.

Astra medium deep review at exact head 69e7589.\n\nAPPROVE. No verified P0/P1/P2 finding. The loaded UUID path avoids decode/string/interface boxing while preserving UUID equality and the same 16-byte Bloom hash input; loaded/base/tail behavior, null/duplicate handling, liveness selection, scratch cleanup, and per-query ownership were checked. No new wait, shared mutation, leak, or concurrency defect found.\n\nTests cover accepted representations, Bloom hits/misses, malformed/truncated rows, stale scratch, score preservation, duplicates, streams, and parallel owners. Exact-head CI passed build, Ubuntu UT, SCA, coverage, Proxy BVT, pessimistic BVT, and CI Required; changed membership BVT was 49/49 with zero ignored in 0.41s.\n\nNon-blocking note: benchmark/SQL throughput and cgocheck2 were not independently reproduced; existing #28985 COPY ALTER skip is unrelated to this PR.

@aptend aptend 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.

Reviewed exact head 69e7589 against base 5bf6d24. I read the complete six-file diff plus all historical reviews, inline discussion, author replies, and the still-open benchmark thread.

No blocking issue found. The loaded UUID path now parses directly into query-owned, per-segment scratch and exposes pointer-free backing to CGo; the immutable loaded segment, build-side typed fallback, persisted docmap representation, and wire behavior remain unchanged. The tests cover accepted UUID representations, hit/miss/mixed probes, malformed and invalid rows failing closed, exact score/liveness/stream behavior, independent parallel owners, and zero steady-state allocations. BVT covers filter pushdown enabled/disabled.

Exact-head CI is green. Local validation: diff-check/gofmt clean; focused UUID membership tests pass; full ./pkg/fulltext2 passes normally and under -race; TestLoadedUUIDMembershipParallelOwners passes 100 race repetitions. Benchmark shows pointer-backed hit/miss/mixed at 0 B/op and 0 allocs/op versus inline-copy at 16 B/op and 1 alloc/op, with lower latency in each case.

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 size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants