Problem
Scene generation in lib/hooks/use-scene-generator.ts runs strictly serial — content → actions → TTS, one outline at a time (see the // Serial generation loop at line ~329). For an N-scene classroom this is N × (content + actions + TTS) of wall-clock latency, which dominates the post-outline wait.
Proposal
A hybrid two-phase parallel mode:
- Phase 1 — concurrent content.
Promise.all over pending outlines (capped) to fetch /api/generate/scene-content. Failures mark individual outlines and don't pause the batch.
- Phase 2 — serial actions + TTS. Keep the current in-order for-of loop for
/api/generate/scene-actions + TTS so that previousSpeeches threading and the pause-on-failure UX stay intact.
This keeps narrative coherence (previousSpeeches carryover) and ordered UI rendering, while parallelizing the heaviest per-scene LLM call. Expected speedup ≈ 2–3× at concurrency 3.
Configuration
- Gated by a server-side config flag, default OFF.
- Concurrency is configurable (e.g.,
PARALLEL_SCENE_CONCURRENCY, default 3 when enabled).
- Rationale for default-off: many users bring API keys with low per-key concurrency quotas; a bursty default would surprise them with 429s. Opt-in keeps the out-of-box behavior unchanged.
Out of scope
- A "full parallel" path (content + actions + TTS all concurrent) — would break previousSpeeches coherence.
- The
classroom-job-runner.ts server path is also serial today but is not on the web critical path; can adopt the same pattern later.
- The unused
generateFullScenes in lib/generation/scene-generator.ts (no callers) — worth removing as cleanup alongside this work.
Problem
Scene generation in
lib/hooks/use-scene-generator.tsruns strictly serial — content → actions → TTS, one outline at a time (see the// Serial generation loopat line ~329). For an N-scene classroom this is N × (content + actions + TTS) of wall-clock latency, which dominates the post-outline wait.Proposal
A hybrid two-phase parallel mode:
Promise.allover pending outlines (capped) to fetch/api/generate/scene-content. Failures mark individual outlines and don't pause the batch./api/generate/scene-actions+ TTS so thatpreviousSpeechesthreading and the pause-on-failure UX stay intact.This keeps narrative coherence (previousSpeeches carryover) and ordered UI rendering, while parallelizing the heaviest per-scene LLM call. Expected speedup ≈ 2–3× at concurrency 3.
Configuration
PARALLEL_SCENE_CONCURRENCY, default 3 when enabled).Out of scope
classroom-job-runner.tsserver path is also serial today but is not on the web critical path; can adopt the same pattern later.generateFullScenesinlib/generation/scene-generator.ts(no callers) — worth removing as cleanup alongside this work.