Repository navigation
perf(xerj-autoindex): O(1) journal state writes and per-replay lookups (#1224 client CPU) - #1228
Merged
Merged
Conversation
#1224's original report measured ~0.66 s of client CPU per file during cve-records apply. The client no-op delete gate (#1225) and the server-side no-flush gate (#1227) removed the delete_by_query storm, but the re-measure still ran at 1.18 items/s with the client pinning one core in pure user time (82% of a core, 0 kernel ticks) at 5.7 GB RSS. The original per-file CPU claim was right for a reason nothing had profiled yet: the parked delete stacks of the first gdb probe masked it. Root cause: Journal::sync_operation_state runs twice per replayed operation (Started + Committed), and each call cloned the ENTIRE PendingSync - desired GenerationManifest with all 402,695 groups, the 402,744-entry operations Vec, and the growing operation_states map - before appending one small durable line. Two full deep clones per file, plus three more quadratics hiding behind them: - PendingSync::apply_operation_state validated membership with a linear operations.iter().any() per state event, both live and again on every journal load-replay (2 events per operation). - EsSyncBackend::apply_shared resolved each operation's group with base/desired groups.iter().find() over every group, per operation. - replay_prepared resolved each content_id with a linear scan of the snapshot's 402k files, per upsert. Fix, all client-side, event format and semantics unchanged: - sync_operation_state: validate (pure) -> durable append -> record in place. The journal line is the transaction boundary; a crash between append and record loses nothing because load replay rebuilds the map from the file, and a failed append returns before any mutation, the same guarantee the clone-on-write provided. - PendingSync carries a lazily-built, never-serialized OperationIdIndex (HashSet + len guard) so membership is O(1); apply_operation_state is now validate+record so load replay shares the fast path. - EsSyncBackend builds a ReplayLookup (group_id and content_id to position maps for base, desired and snapshot) once per replay_operations call. Hits are verified against the slice they answer from and length-guarded, so a stale or absent cache falls back to the exact scan it replaces. Pattern reference (approach, not code): redb's InMemoryState - the durable structure is the truth, in-memory state is a derived cache updated after the durable commit and rebuilt on load (redb src/tree_store/page_store/page_manager.rs:252, Apache-2.0/MIT). Measured, cve-records (402,695 files, 1.9 GB prepared) against the isolated rc.89-gate node on :19285: apply phase 1.18 items/s before this change (0.72 s client CPU per file); after-numbers land on #1224 as the resumed run reaches the apply phase. Tests: operation_state_split_semantics_and_membership_index_hold pins the validate/record split, the pre-split transition rules, the clone-carried index, and the len guard against stale-shape answers. Full xerj-autoindex lib suite 1299 passed / 0 failed. Files: - engine/crates/xerj-autoindex/src/state.rs :: sync_operation_state - engine/crates/xerj-autoindex/src/sync.rs :: PendingSync, OperationIdIndex, validate/record_operation_state - engine/crates/xerj-autoindex/src/sync_executor.rs :: ReplayLookup, EsSyncBackend::{apply_shared, replay_prepared, replay_metadata, replay_operations}
…test CI clippy runs --workspace --all-targets -D warnings; the two operation_states.get(..).is_none() asserts in the new test trip unnecessary_get_then_check. contains_key says the same thing. Follow-up to cc5f3a9 on the same branch.
This was referenced Oct 7, 2026
Merged
thomas-villani
pushed a commit
to thomas-villani/xerj
that referenced
this pull request
Oct 9, 2026
Workspace version + Cargo.lock (17 member entries). Release window: xerj-org#1219, xerj-org#1223, xerj-org#1225, xerj-org#1227, xerj-org#1228.
thomas-villani
pushed a commit
to thomas-villani/xerj
that referenced
this pull request
Oct 9, 2026
Window: xerj-org#1219 (Vinz2168 field report, closes the xerj-org#1091 tracker it diagnoses), xerj-org#1223 (kNN exact-scan capture bracket, xerj-org#1220), xerj-org#1227 (no-match by-query must not flush, xerj-org#1222), xerj-org#1225 (visibility probe gates the per-group delete), xerj-org#1228 (O(1) journal state writes, the xerj-org#1224 client-CPU leg). Release-notes gate: PASS locally (release-notes-gate.sh against origin/main) after the gate itself caught the xerj-org#1224 claims-it-whole drift in the first draft - the entry now says the tracker closes on the completed re-measure, not on the legs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The #1224 re-measure (after both delete gates, #1225 client + #1227 server) still ran the cve-records apply phase at 1.18 items/s, the client pinning one core in pure user time at 5.7 GB RSS. The original per-file client-CPU claim in #1224 was right; the first gdb probe's parked delete stacks had masked it. This PR removes the client-side cost.
Root cause
Journal::sync_operation_stateruns twice per replayed operation (Started + Committed). Each call cloned the entirePendingSync—desiredmanifest with all 402,695 groups, the 402,744-entryoperationsVec, the growingoperation_statesmap — to append one small durable line afterward. Two full deep clones per file.Behind it, three more quadratics over the same corpus run:
state.rssync_operation_stateclonesync.rsapply_operation_statemembershipiter().any()sync_executor.rsapply_sharedgroup resolutionsync_executor.rsreplay_preparedartifact resolutionChange
sync_operation_state: validate (pure) → durable append → record in place. The journal line is the transaction boundary; a crash between append and record loses nothing (load replay rebuilds from the file), and a failed append returns before any mutation — the same guarantee the clone-on-write gave.PendingSyncgains a lazily-built, never-serializedOperationIdIndex(HashSet + len guard) so membership is O(1) live and on load replay.EsSyncBackendbuilds aReplayLookup(group_id / content_id → position for base, desired, snapshot) once perreplay_operations; hits are verified against the slice they answer from, length-guarded, scan fallback outside a replay.Event format, transition rules and observable journal behavior are unchanged. Pattern reference (approach only): redb's
InMemoryState,page_manager.rs:252— durable structure is the truth, in-memory state a derived cache (Apache-2.0/MIT).Numbers
cve-records, 402,695 files / 1.9 GB prepared, isolated rc.89+gate node on :19285:
Tests
operation_state_split_semantics_and_membership_index_hold(split semantics, pre-split transition rules, clone-carried index, len guard).cargo test --release -p xerj-autoindex --lib: 1299 passed / 0 failed.