Repository navigation
perf(judge): warm the screenshot cache before the parallel samples - #143
Merged
Merged
Conversation
All judge samples of a screenshot share the cached prefix (system prompt + image), but they were sent at the same time, so every call missed the cache and wrote it (1.25x input) and none read it. runLayer3 now sends one sample first, then the rest together (firstThenTogether), so they read the cache (0.1x input). Measured on the same iOS home screenshot with DEFAULT_STAGE1_RUBRIC (2 criteria x 3 samples): 1 cache write + 5 cache reads, $0.054 per platform instead of $0.152 (-65%). README cost table updated: VISUAL=1 ~$0.13 (was ~$0.32), VISUAL=2 ~$0.24 (was ~$0.62). Adds a few seconds per platform. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K5hZEFqXhBsUQwSWsgR6eH
Merged
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.
Problem
#142 showed every judge call writing the screenshot cache and none reading it: a rubric's samples (2 criteria × 3) were sent in parallel, so all of them missed the cache. Caching made the judge ~25% more expensive than no caching.
Fix
firstThenTogether()runs the first sample alone (writes the cache), then the rest together (read it). Results keep rubric order; the per-criterion majority vote is unchanged.Measured (real calls, same iOS home screenshot, DEFAULT_STAGE1_RUBRIC)
README: VISUAL=1
$0.32 → **$0.13**, VISUAL=2$0.62 → **$0.24**, judge retry ~$0.15 → ~$0.05 per platform. Costs a few extra seconds per platform (one call before the batch).Tests
New smoke test for
firstThenTogether(first call finishes before the rest start; the rest run concurrently; order kept) — red when the helper runs everything in parallel, green after.npm run ci: 157 pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01K5hZEFqXhBsUQwSWsgR6eH