Skip to content

perf: read ahead only the records a listing of the store's keys finds - #48

Merged
metalwarrior665 merged 2 commits into
masterfrom
perf/prefetch-by-key-listing
Nov 17, 2026
Merged

metalwarrior665 merged 2 commits into
masterfrom
perf/prefetch-by-key-listing

Conversation

@metalwarrior665

Copy link
Copy Markdown
Member

At Actor::init, each record of InitOptions::prefetch_records (and the tracked child runs) got its own GET. A fresh run of google-maps-rs prefetches ~10 state records that mostly don't exist yet, so it sent ~10 GETs that all answer 404.

What changed:

  • At init, the default store's keys are listed once (pages of 1,000, at most 10). The listing runs in the background next to the metadata read.
  • Only the records the listing finds are fetched. Those GETs run in parallel once the listing returns. The first get_value of a prefetched key that isn't listed returns None with no API call.
  • INPUT is still fetched right away, alongside the listing, because a run nearly always has it.
  • A set_value/delete_value of a key drops what was read ahead for it, so the next read goes to the API, as before.
  • If the listing fails, or the store holds more than 10,000 keys, each record is fetched as before.
  • The listing includes records written by an earlier container of the run, because the platform stores a record before it answers the write.

Fresh run: metadata + 1 listing + INPUT, where it used to be metadata + INPUT + one GET per prefetched key. Resumed run: the records that exist are fetched one round trip later, after the listing.


Generated by Claude Code

At `Actor::init`, every record of `InitOptions::prefetch_records` (and the
tracked child runs) was read with its own GET. Most of them are state an
earlier container of the run would have saved, so in a fresh run they do not
exist and each GET answers 404: a run prefetching ten records made ten calls
for nothing.

Now the store's keys are listed once (pages of 1,000, at most 10), in the
background beside the metadata read, and only the records listed are read,
all at once after the listing. The first read of a record that is not listed
is `None` without an API call. The input is still read at once, beside the
listing, as a run nearly always has it. A record written or deleted through
the SDK is read from the API again, as before. When the listing fails or the
store holds more than 10,000 keys, each record is read as before. The
listing is complete for records an earlier container wrote: the platform
stores a record before it answers the write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S
…more

Paging through up to 10,000 keys would cost more than the reads it saves:
a store holding more than one page (1,000 keys) has its records read one by
one, in parallel, as before the listing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S

Copy link
Copy Markdown
Member Author

Two updates in a2ad836:

The listing reads one page of keys now. A store holding more than one page (1,000 keys) has its prefetched records read one by one, in parallel, instead of being listed page after page up to 10,000. a_store_with_more_keys_than_the_listing_covers_falls_back_to_reading_each_record now uses 1,001 keys and expects exactly one listing call. It failed before the change.

A listing takes about as long as a record read. I timed requests against a real run's default store (8 keys), 25 times each, interleaved, from outside the platform:

Request Median p10 p90
List keys (limit=1000) 162 ms 148 ms 211 ms
Get an existing 1 KB record 163 ms 146 ms 188 ms
Get an existing 26 KB record 183 ms 167 ms 208 ms
Get a missing record (404) 149 ms 130 ms 184 ms

So a fresh run trades about ten missing-record reads for one listing that takes about as long as any one of them.

🤖 Generated with Claude Code

https://claude.ai/code/session_0148RYR4BTGyCYHENSRZjC3S


Generated by Claude Code

@metalwarrior665
metalwarrior665 merged commit d2c9bf3 into master Nov 17, 2026
6 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.

2 participants