← Back to Pull requests

perf(core): read small store files into owned memory at open #7373

Closed
unknown closed this pull request without merging on Nov 13, 2026 11:31 UTC
View on GitHub
unknown unknown commented on Nov 13, 2026 10:29 UTC
Author

<!-- claude-projects-attribution: {"github_login":"jeswr"} -->
_Requested by Jesse · project thread_

Addresses #7188.
Addresses #7370.

Summary

Small persisted dictionary sections, caches and permutations are now read into owned memory through a shared internal opener; larger files stay mapped. Owned data is decoded as typed little-endian values, so alignment is never an issue. Dictionary and compressed-index validation is shared by both backings, and a fully mapped dictionary still passes direct byte views to that shared validator.

The size cutoff is internal and is set from the native resource-slot file size distribution. Owned memory counts toward heap accounting. Ownership pins, fork sharing, persisted bytes and persistence ordering are unchanged. The data-formats skill is updated, and the Miri lane now covers the owned path. Test scratch directories skip existing paths and leave their contents alone.

An internal compiler cfg selects mapped or owned backing for the whole test suite, including integration tests that link the library outside its unit-test build. Only the threshold helper reads it, and the thread-local test override takes precedence. Owned mode uses the largest addressable size with a saturating read limit. The numeric and temporal caches no longer repeat a length check, because the shared opener already enforces it.

A new matrix job in ci-fast runs the complete core storage suite once per backing mode on every workflow trigger. It has no path filter or conditional skip, and it is not a dependency of the required aggregator. Existing jobs, triggers and the required verdict are unchanged.

Base gate (always required)

  • Builds and tests were crate-scoped; no separate workspace build was run.

  • cargo clippy --workspace --exclude sparq-py --all-targets -- -D warnings: passed.

  • cargo test -p sparq-core: passed.

  • cargo test -p sparq-core --features mmap,dict-spill, once with RUSTFLAGS='--cfg sparq_backing="mapped"' and once with RUSTFLAGS='--cfg sparq_backing="owned"': passed, including unit tests, integration tests and doctests. Each mode used its own temporary target directory, removed afterwards.

  • The new backing-selection test also passed with no compiler selector, which exercises the production cutoff.

  • cargo test -p sparq-core --no-default-features --features mmap: passed on the initial implementation.

  • cargo test -p sparq-lws-core and its --no-default-features variant: passed. The remote HTTP adapter is unchanged.

  • RUSTDOCFLAGS="-D warnings" cargo doc -p sparq-core --no-deps --all-features: passed.

  • New files are formatted; existing files keep their surrounding style. No workspace-wide reformat.
  • Targeted re-evaluation (check the rows that apply to your change)

  • The complete crash, fault, journal, layout, swap, corruption, snapshot, descriptor and directory-lock tests passed in both compiler-selected modes. In mapped mode every nonempty immutable backing file is mapped, including small corruption fixtures; in owned mode every immutable backing file is read into owned memory. Representation-specific tests keep their local overrides.

  • The Windows-only detached-child test now forces the mapped backing. Its scenario depends on open file mappings blocking a directory rename, and owned small files no longer hold mappings open.

  • Raw and compressed save-byte differentials, journal replay, clean-close tree identity, and opens in both directions against the pre-change baseline all passed. No separately published release reader was tested.

  • The deterministic storage, dictionary and wasm byte gates passed, as did the wasm dependency guard.

  • Paired large-graph open and query comparisons, with an identical-binary control, showed no detectable regression. The measurements are kept privately.

  • The native durable HTTP harness passed its restart and body checks. Same-size HTTP-built and synthetic fixtures had matching file and mapping counts on the pre-change baseline, before and after compaction. The full HTTP-tier re-measurement waits until the read-plan and exact-name changes are merged.

  • The existing store-opening fuzz target passed corpus replay and a bounded randomized run, through an isolated harness built from the same target source.

  • Passed: preflight with explicit changed-file and added-line inputs, actionlint on all workflows, the workflow-label tests, a structural check that the new matrix is added and the required jobs are unchanged, the unsafe register check, markdown lint and git diff --check.

  • The initial implementation also passed the config-documentation, feature-test executor and unsafe-count checks. The earlier server, fuzz, byte and measurement checks above still apply, since this revision only changes how tests select a backing and the bounded-read arithmetic.
  • Existing mapped-path guards are kept, with the mapped path now selected explicitly:

  • open_recomputes_an_unversioned_numerics_cache: stale-cache recomputation, and that a current cache is mapped when the mapped path is forced.

  • save_open_mmap_roundtrip: term, numeric and temporal values through the mapped path.

  • has_high_precision_decimal_memo_mapped_wal_precision: precision classification across mapped reads, logged updates and compaction.

  • compressed_save_open_roundtrip: raw mapped references against lazy and eager compressed scans and estimates.
  • Tests and executed mutation checks are listed below. Each mutation is a token change at the named source location, and each was restored. The decoder and replay mutations are caught by test assertions, which replaces earlier evidence that relied on a decoder panic. Mutant tests ran normally, and the restored owned-open test also ran under Miri.

    | Test | Contract checked | Minimal source mutation | Observed failing assertion |
    |---|---|---|---|
    | scratch_paths_do_not_reuse_existing_directories | A stale scratch directory is left alone and a fresh path is chosen. | Replace the existing-path continue branch with return Self(path). | The selected-path equality assertion fails. |
    | build_selection_and_override | The compiled selection decides the actual backing for empty, small and above-cutoff files; bytes agree; the maximum and nested mapped overrides work and restore correctly. | At the open_file call site, replace the threshold() argument with SMALL_FILE_BYTES; separately, make that replacement apply only to small files. | In the mapped-mode run, the backing-kind equality fails with build selection ignored for file length. Both mutations were restored and the test passed again. |
    | threshold_boundaries_and_empty | Empty files and files exactly at the cutoff get the correct backing, with bytes preserved. | Change <= to < in the size-selection predicate. | wrong backing at boundary |
    | changed_size_is_bounded_and_refused | A file that grows (within or beyond the cutoff) or shrinks to empty between stat and read is refused; reads stop at the bounded sentinel. | Replace the size-change predicate with a beyond-cutoff-only predicate; separately, replace read_limit at take with the integer type's MAX. | changed-size file was accepted; the read mutation fails read exceeded its bound. |
    | mapping_failure_names_limit | A mapping error carries its typed diagnostic; other errors keep their kind. | Replace the mapping-error classification predicate with false. | The error-kind equality assertion fails. |
    | owned_and_mapped_graphs_match | Expected source and replayed rows, dictionary lookup, caches, every binding pattern, forks, saved bytes and heap accounting agree across backings. | In the dictionary hash decoder, replace from_le_bytes with from_be_bytes. | Dictionary lookup equality fails: an absent ID where the expected ID should be. |
    | owned_open_miri | Owned dictionary, raw and compressed permutations, numeric and temporal caches, and forks round-trip under Miri. | The same hash-decoder replacement. | Dictionary lookup equality fails. The restored test passed under Miri. |
    | Both owned differential tests | Numeric decoding preserves values and missing cache entries. | In the numeric cache decoder, replace from_le_bytes with from_be_bytes. | numeric cache changed |
    | owned_and_mapped_graphs_match | Recovery applies the expected insertions and deletions. | Replace WAL replay iteration with an empty iterator. | replay changed rows |
    | small_corruption_matches_mapped_errors | Both backings return the same errors for malformed dictionary and compressed files. | Remove the MappedDict::validate call. | corruption was accepted |
    | tiny_slots_hold_no_file_mappings | Reopened tiny slots hold no file mappings, before or after durable compaction. | Replace the size-selection predicate with an empty-file-only predicate. | small slots retained file mappings |

    Ratchets and conventions

  • No conformance, performance or coverage floor was lowered. The unsafe snapshot was tightened and the unsafe register reconciled.

  • Measurements and their interpretation stay in private reports.

  • No new public configuration or on-disk format.

  • Follow-up: repeat the full HTTP-tier measurements after the read-plan and exact-name work is merged. Any further layout work depends on that evidence.
  • 🤖 Generated with Claude Code

    https://claude.ai/code/session_01JLKBH5gHei9rJAmvhNgZyi

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jeswr Review duration: 62m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #7373"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%