Skip to content

perf(sessions): batch canonical observation body reads - #4738

Closed
ScriptedAlchemy wants to merge 1 commit into
masterfrom
perf/session-body-hydration-batching-20261103
Closed

ScriptedAlchemy wants to merge 1 commit into
masterfrom
perf/session-body-hydration-batching-20261103

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Finding

The canonical observation decoder issues one awaited SQLite query per distinct content hash, including from the existing batched session projection-observation read. A single observation with many large fields therefore serializes round trips to the same registered store, even though the body hashes are already known together.

Change

  • Load canonical body rows in SQL IN batches of at most 16 distinct hashes. The existing observation-to-body authority, store identity, and transaction/snapshot still govern the read; this creates no second cache or worker.
  • If an exact-SQL result exceeds its existing materialization ceiling, split the page, down to the original one-body operation. Other SQL failures remain typed errors.
  • Decode and SHA-256/size-verify each body in the original sorted-hash order, independently of SQLite's result order. Missing and corrupt hashes still refuse. Repeated references share one lookup and remain hydrated through the canonical parser.
  • No admission, persistence format, authorization, retention, mutation, or deadline policy changes.

Regression

An actual SQLite-backed TestConnection fixture builds one valid observation containing 18 distinct external bodies and a repeated body reference. A query-counting adapter on the real read port requires 2 bounded SQL reads instead of 18. It also checks the fully reconstituted observation and typed missing-body and hash-corruption refusals.

Verification / limits

  • Independently reviewed the isolated one-file commit against current master adbf0e391bd7; GitHub comparison confirms one fast-forward commit changing only crates/tracedecay-session-temporal-store/src/query.rs. Checked error precedence, identity, deduplication, parameter bounds and materialization fallback at source level.
  • Not executed: Bazel, rustfmt, Rust compilation, the added test, or runtime benchmarks. This environment has no supplied checkout or Bazel/Rust toolchain. Hosted CI needs to run bazel test //crates/tracedecay-session-temporal-store:unit_test --test_output=errors and formatting on this exact head. A query-count regression is not an elapsed-time speedup measurement.
  • Separate PR/CI automation owns test repairs and merge decisions. Keep this draft until isolated-head validation passes.

This is a focused hot-path optimization found while reviewing open performance/storage issues; it does not claim to resolve the broader corpus, graph publication, or storage-growth incidents.

@changeset-bot

changeset-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: acfc0b2

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

@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

Consolidated into #4742 (integrate/open-pull-requests) at the captured head shown in its description, as requested. Continue review and further fixes on #4742. This closure does not assert CI readiness; the replacement remains draft. Source branch retained.

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