Skip to content

perf(visual): run visual-diff LLM calls concurrently instead of serially - #177

Open
JonasJesus42 wants to merge 1 commit into
mainfrom
perf/parallelize-visual-diff-llm
Open

perf(visual): run visual-diff LLM calls concurrently instead of serially#177
JonasJesus42 wants to merge 1 commit into
mainfrom
perf/parallelize-visual-diff-llm

Conversation

@JonasJesus42

@JonasJesus42 JonasJesus42 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Problem

In runVisualRegression (src/checks/visual-regression.ts), the finalize loop called await visualSemanticDiff(...) inline, one page at a time:

for (const p of prepared) {
  ...
  } else if (llmTargets.has(p)) {
    const diffs = await visualSemanticDiff({ ... }); // serial
  }
}

Each visualSemanticDiff is 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 a Map<PreparedPair, ...>, then read them in the (still-sequential) finalize loop:

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.ts 18 tests and tests/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.all to reduce wall-clock time by up to ~3× on uncached pages, while keeping finalize order, cache writes, and counters deterministic.

  • Performance
    • Kick off eligible visualSemanticDiff calls in parallel and store outcomes in a Map for sequential finalize.
    • Concurrency stays bounded by the existing semaphore (MAX_CONCURRENT_LLM_CALLS), avoiding OOM and preserving deterministic result and issue ordering.

Written for commit 4f5994e. Summary will update on new commits.

Review in cubic

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>
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