perf(visual): run visual-diff LLM calls concurrently instead of serially - #177
Open
JonasJesus42 wants to merge 1 commit into
Open
perf(visual): run visual-diff LLM calls concurrently instead of serially#177JonasJesus42 wants to merge 1 commit into
JonasJesus42 wants to merge 1 commit into
Conversation
The finalize loop awaited visualSemanticDiff() one page at a time, so the whole batch of visual-diff LLM calls ran serially — even though the LLM client already has a concurrency semaphore (MAX_CONCURRENT_LLM_CALLS = 3) that permits up to 3 in flight. Each call is a multimodal request with 2-3 large screenshots and takes several seconds, so serializing N non-cached pages was a major chunk of the visual-diff phase wall-clock. Fire the LLM calls up front with Promise.all and read the resolved outcomes in the (still-sequential) finalize loop, preserving deterministic result ordering, cache writes, and issue ordering. Real parallelism — and thus peak memory from the base64 image payloads — stays bounded by the existing semaphore, so this doesn't reintroduce OOM pressure. Wall-clock for the visual-diff phase drops by up to ~3× on runs with several uncached pages. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
In
runVisualRegression(src/checks/visual-regression.ts), the finalize loop calledawait visualSemanticDiff(...)inline, one page at a time:Each
visualSemanticDiffis a multimodal LLM request carrying 2-3 large screenshots and takes several seconds. The LLM client already exposes a concurrency semaphore (MAX_CONCURRENT_LLM_CALLS = 3), but awaiting each call before starting the next meant only one ever ran at a time — the allowed parallelism was wasted. On a run with several non-cached pages this serialization was a large chunk of the visual-diff phase wall-clock.Fix
Fire the LLM calls concurrently up front with
Promise.all, store the outcomes in aMap<PreparedPair, ...>, then read them in the (still-sequential) finalize loop:setCacheEntry), counters (llmCallsUsed/pagesFromCache), and issue ordering all stay deterministic — only the network calls overlap.Visual-diff phase wall-clock drops by up to ~3× on runs with several uncached pages.
Verification
bun run check(tsc) passes.bunx vitest run— full suite: 995 tests passing (incl.tests/checks/visual-regression.test.ts18 tests andtests/llm/visual-semantic-diff.test.ts), which cover the LLM path, cache path, ordering, and counters.Performance follow-up to the memory-pressure series (#173, #174, #175, #176).
🤖 Generated with Claude Code
Summary by cubic
Run visual-diff LLM calls concurrently using
Promise.allto reduce wall-clock time by up to ~3× on uncached pages, while keeping finalize order, cache writes, and counters deterministic.visualSemanticDiffcalls in parallel and store outcomes in a Map for sequential finalize.MAX_CONCURRENT_LLM_CALLS), avoiding OOM and preserving deterministic result and issue ordering.Written for commit 4f5994e. Summary will update on new commits.