Skip to content

perf(query): bound large-document ngram deduplication - #5012

Merged
ScriptedAlchemy merged 10 commits into
masterfrom
fix/lexical-artifact-publication
Nov 29, 2026
Merged

ScriptedAlchemy merged 10 commits into
masterfrom
fix/lexical-artifact-publication

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 29, 2026 •

Copy link
Copy Markdown
Owner

Why

Large generated documents repeat many one-, two-, and three-byte windows. The current projection appends every window before sorting and deduplicating it, during both page preparation and final posting derivation. This consumes publication time in the exact-import MCP journey. The investigation began after the release candidate for #4985 exceeded its existing publication deadline following #5005.

Change

Deduplicate sufficiently large documents through a dense presence bitmap only when the bitmap plus the maximum possible unique output fit the existing admitted scratch allocation. Enumerate keys in the existing numeric order and reuse that allocation for the result. Smaller inputs retain the original sort path.

The implementation preserves the 64 MiB scratch ceiling, all byte values including NUL and UTF-8, ordering, and cancellation during input scanning and output extraction. Regression tests compare the dense output with an independent set of byte windows and test cancellation in both phases. Canonical layout, persisted format, and reader validation remain unchanged.

Measured result

Paired CI 46240345433 ran exactly 1 test with 320 filtered in 12.96 seconds under the canonical Bazel query-unit opt-level 1 configuration. It recorded seven inputs × eight pairs, with four old-first and four dense-first rounds for every input. Both algorithms used identical admitted scratch and cancellation checks; setup, warm-up, parity/capacity checks, and deallocation stayed outside timing. All parity/capacity assertions passed, with no timing assertion.

Input Bytes Old median Dense median
repeated 204,000 72.552 ms 8.888 ms
all_bytes 204,800 106.353 ms 9.099 ms
utf8 220,000 67.724 ms 10.020 ms
varied 200,000 136.185 ms 10.918 ms
ModuleFederationPlugin 546,888 239.501 ms 22.161 ms
ContainerPlugin 718,620 301.765 ms 28.621 ms
SharePlugin 890,764 373.414 ms 35.070 ms

The three generated validator contents measured 10.54–10.81× faster in this kernel. This is specific to the tested configuration and inputs; it does not establish production throughput or a whole-publication latency guarantee. Earlier four-fixture hosted totals of 17.54 seconds and 5.01 seconds had material host/phase and merge-base differences, so that total-time difference is not attributed to this algorithm.

Full-CI findings and fixture corrections

Normal CI 46243838650 tested merge 883323cf, combining the prior PR head with master 828fd99e. It passed 179/182 targets (78 executed, 104 cached). Clippy passed. The failures were the global-db unit target's 300.2-second aggregate timeout; two core CLI cases (208 passed, 2 failed); and the MCP peer-composition fixture (681 passed, 1 failed). The query target reused its valid 319-passed/1-ignored result.

This update integrates already-merged master 64d43ed4 and repairs the evidenced setup preconditions:

  • The old checkout lacked perf(workflow): batch schema admission on one reader snapshot #5013's existing lazy graph-attachment fixture correction. The current global-db suite has 589 cases; its seven missing completion records all used the old eager helper. No individual hang or guaranteed aggregate-time improvement is inferred from the cutoff. The updated base must pass the unchanged full target.
  • The CLI branch-list fixture previously treated successful compact status as a fully settled project. Compact status can succeed on Core before full branch diagnostics are available. Setup now requests full diagnostics through the existing generic tool warm-up path, bounded by the remaining original 90-second setup allowance. All 300 references and both real branch-list assertions are unchanged.
  • The MCP peer helper still mounts the same real production owners, stores, leases, workers, and shutdown path. It leaves code-index readiness to callers: the file-inventory caller retains its explicit 20-second readiness wait; the operation-history lifecycle caller does not consume the peer index. Its independent request admission, peer shutdown, surviving sequence, and terminal-receipt assertions remain unchanged.
  • The branch-add provenance test keeps its original 30-second assertion and all artifact/removal checks. It now retains ordinary daemon stderr through the existing logged-daemon helper and includes that log on failure. The earlier publication timeout's cause remains unproven; this change improves its evidence rather than claiming a production repair.

The two publication fixtures have tiny source inputs below the dense-path threshold. That excludes direct execution of the new bitmap path in those fixtures, but does not establish the cause of their timing failures.

Persistence diagnostic and validation

The earlier observability_persistence_deadline failure did not recur. The complete diagnostic ran all 442 daemon-service tests with zero filtering in 24.39 seconds; the previously failing test passed. Its observed claim/settle transactions were about 2.009 and 1.700 ms, final carrier batch 0.717 ms, and producer shutdown 6.429 ms. Trace overhead and isolated-target load differ from full-fleet CI; this is a measured pass, not a historical timeout fix. The subsequent normal run also passed all 442 daemon-service tests in 45.57 seconds.

  • At e7d1d971, pinned Rust 1.100.1 formatting, commitlint, and diff checks passed for the fixture corrections; independent reviews checked the exact three final file blobs and integration ancestry.
  • The e7d1d971 revision removed its temporary timing/tracing scaffolds, test filters, and diagnostic workflow changes. At that revision, the diff against the integrated base contained the posting implementation/regressions and two fixture files: 170 additions, 11 deletions. The later persistent diagnostics and shared hook-fixture correction are described below.
  • The full standard CI 46248194706 on e7d1d971 passed Repository gates, Clippy, Dashboard, Feature gates, and Windows. Linux passed 181/182 targets. The sole remaining failure was receipt_survives_restart_between_sse_frame_and_browser_ack: its receipt assertions completed, but producer shutdown returned the retained observability_persistence_deadline error.

Persistence failure diagnosis

Commit cbe89f0c adds operation names at persistence timeout sites and existing tracing spans around producer/outbox phases. The receipt restart fixture captures span-close busy/idle timings through the existing thread-local helper. All error retention, receipt/restart assertions, test selection, and persistence/shutdown deadlines are unchanged.

The completed diagnostic Linux run 46291957115 passed all 182 targets: 120 executed and 62 cached. The dashboard unit suite executed uncached and passed in 3.2 seconds. The original receipt timeout did not recur. Passing test output is suppressed by the normal CI configuration, so this run supplies no receipt-phase timings and does not establish a repair of the historical timeout. Independent lifecycle review found no premature database-owner drop or lock held across outbox admission; error retention and deadlines remain unchanged.

That run also identified a one-line rustfmt correction in the trace-capture declaration. Commit f044f322 applies the exact correction, verified locally with the pinned Rust 1.100.1 formatter after executor access recovered.

Shared hook-fixture correction

Commit b7a9ccf2 carries the independently reviewed fixture correction from #5024 onto this engineering branch. A retained Stop retry now waits for the exact event's single durable completed settlement as well as a drained replay spool before resubmitting. The existing overall wait budget, suppression assertion, event identity, delivery count, and duplicate checks remain. This exact fixture content passed #5024's normal CI, including its uncached hook suite. It is not a persistence-timeout repair and adds no release/version changes.

The corrected head b7a9ccf2 is pushed. Current canonical CI 46298864221 has passed Repository gates (including formatting), Clippy, Dashboard, Feature gates, the benchmark harness, and Linux. The Linux fleet job passed all 182 test targets: 74 executed and 108 cached. The changed hook suite executed in 19.7 seconds and dashboard unit suite in 21.9 seconds; both passed. The application suite also executed successfully (60.3 seconds); the global-db target reused its valid 230.4-second cached pass. The original receipt timeout again did not recur, without establishing a causal repair. The Windows job subsequently built and type-checked all 515 targets and passed the Node-held-addon upgrade-refusal check. The workflow and Devin review are now successful. This PR was merged as fab2cde7; Windows completed successfully after the merge.

Refs #4985. Follow-up to #5005.

@changeset-bot

changeset-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b7a9ccf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot 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.

🔍 Devin Review: 2 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

@ScriptedAlchemy
ScriptedAlchemy enabled auto-merge (squash) November 29, 2026 06:55
@ScriptedAlchemy
ScriptedAlchemy marked this pull request as draft November 29, 2026 07:06
auto-merge was automatically disabled November 29, 2026 07:06

Pull request was converted to draft

@ScriptedAlchemy ScriptedAlchemy changed the title chore(test): profile lexical publication (do not merge) chore(test): compare ngram kernels (do not merge) Nov 29, 2026
@ScriptedAlchemy ScriptedAlchemy changed the title chore(test): compare ngram kernels (do not merge) chore(test): trace daemon persistence (do not merge) Nov 29, 2026
@ScriptedAlchemy ScriptedAlchemy changed the title chore(test): trace daemon persistence (do not merge) perf(query): bound large-document ngram deduplication Nov 29, 2026
@ScriptedAlchemy
ScriptedAlchemy marked this pull request as ready for review November 29, 2026 08:41
@ScriptedAlchemy
ScriptedAlchemy enabled auto-merge (squash) November 29, 2026 09:44
Name producer and outbox phases with existing tracing spans and log
the operation when a persistence deadline expires. Preserve the same
typed errors, first-failure retention, persistence and shutdown budgets.

Capture span-close busy/idle timing for the real receipt restart test
through the existing thread-local tracing helper. Keep the full test
and every receipt, replay, acknowledgement and shutdown assertion so
canonical CI can identify which persistence operation causes the
otherwise indistinguishable shutdown failure.
Apply the pinned formatter's one-line declaration without changing
the persistence diagnostic, receipt assertions, or test deadlines.
Carry the reviewed hook fixture repair from 57487cd.
Wait for the exact Stop event's completed durable settlement and a drained
replay spool before resubmission. Preserve the original deadline and final
delivery, suppression, and duplicate assertions.

Keep the shared CI repair on the engineering branch so release-please
regeneration cannot discard it.
@ScriptedAlchemy
ScriptedAlchemy merged commit fab2cde into master Nov 29, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant