Repository navigation
fix(storage): restore index counts from snapshot metadata - #23
Merged
Merged
Conversation
RCmerci
marked this pull request as ready for review
October 1, 2026 12:15
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Restore EAVT, AEVT and AVET cardinalities from the metadata associated with their addresses in the same stored root. Previously the root already held these counts, but restoring the PSS indexes discarded them and subsequent metadata counting traversed every index.
Seed counts before replaying the separate transaction tail so successful edits adjust cardinality exactly once. Current-format snapshots without count metadata retain the existing lazy fallback. For older index-order versions, use the count measured by the existing verification pass; rebuilt indexes derive their count from their actual contents. Negative current-format counts are rejected by the PSS API. Positive metadata is authoritative for its root snapshot; this change does not add a full-tree corruption check.
The required PSS restore API is now merged into official main via logseq/persistent-sorted-set-ocaml#2. The three relevant opam pin-depends entries have been restored to the existing
#mainconvention; other dependency declarations are unchanged. A fresh Git resolution on 2026-10-01 12:06 UTC selecteddf53f5d01c6c77da138f58a5a2da4de181f2adba. Local builds and regressions use the actual library source from that resolved main commit, without modifying the shared opam switch.Before/after probe: native, macOS arm64, OCaml 5.5.0, Dune 3.24.2, synthetic memory storage; 4096 datoms, 2048 indexed, branching factor 32. The two sides use the same data and baseline revisions (DataScript e6ac32c, PSS 879de3b), with only the paired changes on the after side. Index cardinalities are 4096/4096/2048 throughout.
The remaining 333 reads on each store are the unchanged depth traversal. This PR does not remove that cost. The probe counts structure visits, not timing; its observational interface/wrappers are not part of this PR. Unwrapped controls agree with the underlying read counts.
Regression tests cover zero-read repeated counts, successful add/remove, duplicate/absent edits, tail replay and restore_conn, subsequent incremental transactions and re-snapshot, empty indexes, missing metadata, negative metadata, clean legacy indexes with stale counts, and misordered-index rebuilds. Added Melange and js_of_ocaml smoke checks exercise the integration.
Companion dependency PR logseq/persistent-sorted-set-ocaml#2 is merged. This PR now follows PSS main rather than retaining the temporary pre-merge commit pin. DataScript PR #23 remains unmerged.
Local test status:
test_perfAEVT prefix count wall-time gate failed (parallel full run: 0.2947s; isolated run: 0.1684s; fixed threshold: 0.100s). No storage-count assertion failed. The unmodified baseline (DataScript e6ac32c + PSS 879de3b) fails the same gate: Fatal error: exception Failure("AEVT prefix count overhead: counting an AEVT attr prefix should avoid comparator allocation overhead: elapsed=0.3280s"). This shows the gate failure is present without either patch; the isolated timings are single measurements, not a speedup claim.3f141af97b70e1f14c65eaa119acd822ebece37e.No test threshold was changed. The dependency follow-up reran native storage, Conn, SQLite-package, js_of_ocaml smoke and Melange smoke against the resolved PSS main source; all passed. Official CI also completed successfully for the new head
4fc92bbecc0b34b989ba2c82cfed53a32d268439: dependency installation, tests, memory benchmark and benchmark comparison all passed. Run: https://github.com/logseq/datascript-ocaml/actions/runs/36859782729. The CI log confirms installation through the#maindependency URI; it does not print a resolved SHA. The separately recorded Git resolution remainsdf53f5d01c6c77da138f58a5a2da4de181f2adbaat final verification. This PR is still open and unmerged.