Skip to content

perf(store): index latest version lookups - #87

Merged
earakely-scale merged 3 commits into
scaleapi:mainfrom
morluto:codex/perf-version-lookups
Oct 7, 2026
Merged

earakely-scale merged 3 commits into
scaleapi:mainfrom
morluto:codex/perf-version-lookups

Conversation

@morluto

@morluto morluto commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Closes #86

Latest-version reads now use SQLite's existing (id, version) index and decode one document. The typed store and namespace router use the same hook; custom stores retain the existing concrete fallback. Exact-version reads and version-conflict retries retain their semantics.

Latest get

Stored versions Before After Speedup
1 7.51 µs 5.36 µs 1.4×
100 148.97 µs 5.53 µs 27.0×
1,000 1,601.40 µs 6.05 µs 264.6×
5,000 8,281.51 µs 6.10 µs 1,357.3×
Put: initial history Before After Speedup
1,000 1,553.35 µs 49.44 µs 31.4×
5,000 7,511.10 µs 59.96 µs 125.3×

Local medians on Python 3.12.13/macOS arm64; full VersionedEntityStore APIs, 128-byte payloads and 1,000 unrelated IDs. Baseline methods come directly from 05b3310; equivalent fixtures and alternating measurement order. Put samples append 84 versions. These are synthetic local results, not cloud or end-to-end task timings.

Profile proof: 100 latest gets over 1,000 versions decode 100,000 → 100 documents. EXPLAIN QUERY PLAN confirms the compound index; returned latest/exact entities and allocated versions match.

Reproduce: PYTHONPATH=src:packages/agentenv-protocol/src .venv/bin/python tst/benchmarks/version_lookup.py

Validation: 6,325 unit/protocol tests passed, 13 existing capability skips; plugin API check passed. Independent correctness and maintainability reviews are clean.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the earlier benchmark error is addressed and no new actionable issue was established.

What we checked:

  • Benchmark command injection: The command uses a fixed revision and file path. The changed subprocess call does not put a user-supplied value into the command.

Summary

This PR adds an indexed latest-version lookup for SQLite, reducing work on long version histories while keeping exact-version reads unchanged.

  • SQLite reads the latest entity version through its existing index.
  • Version lookups follow the store that owns each entity ID.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Versioned entity store] --> B[Latest-version hook]
  B --> C[SQLite indexed read]
  B --> D[Other store fallback]
  B --> E[Namespace router]
  E --> C
  E --> D
Loading

Reviews (2) · Last reviewed commit: "test(benchmark): cover shallow baseline ..." · Reviewed by Greptile

@morluto
morluto requested a review from a team as a code owner October 7, 2026 01:32
Comment thread tst/benchmarks/version_lookup.py Outdated
@earakely-scale

Copy link
Copy Markdown
Collaborator

Another good PR, thanks @morluto !

@earakely-scale
earakely-scale merged commit 507403f into scaleapi:main Oct 7, 2026
12 of 14 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.

perf(store): avoid decoding full histories for latest versions

2 participants