Skip to content

perf: transcript chunks in /api/v1/events/extract are extracted serially #1337

Description

@groupthinking

Problem

POST /api/v1/events/extract splits a long transcript into overlapping 24 000-character
chunks and then extracts events from them strictly one at a time:

for chunk in transcript_chunks:
    if len(events) >= _MAX_EVENTS:
        break
    for ev in await _extract_chunk(chunk):
        ...

Each _extract_chunk call is an independent, billed Gemini round-trip via
HybridProcessorService.process. Because the loop awaits each one before starting the
next, wall-clock latency is the sum of every chunk's provider latency.

Impact

src/youtube_extension/backend/api/v1/router.py is mounted on the live HTTP surface
(backend/main.py:35 imports v1_router; main.py:164 calls
app.include_router(v1_router)), so this is a user-facing request path, not dead code.

Chunk count grows linearly with transcript length (stride is
_CHUNK_SIZE - _CHUNK_OVERLAP = 23 500 chars):

Transcript Chunks Serial latency @ ~3 s/chunk
30 min talk (~30 k chars) 2 ~6 s
90 min podcast (~120 k chars) ~6 ~18 s
4 h stream (~500 k chars) ~22 ~66 s

The chunks are mutually independent — nothing in _extract_chunk reads state produced by
a previous chunk — so the serialisation buys nothing.

Expected

Extract chunks in bounded windows so independent provider calls overlap, while:

  • keeping the merge in chunk order (dedup and the _MAX_EVENTS budget must select exactly
    the events the serial walk selected);
  • re-checking the _MAX_EVENTS budget between windows so extraction still stops early;
  • keeping failure isolation — one chunk failing must not discard its siblings' events;
  • bounding in-flight billed calls so a very long transcript cannot fan out without limit.

Acceptance

  • Chunks within a window are extracted concurrently (peak in-flight > 1)
  • Peak in-flight is bounded
  • Events are merged in chunk order, not completion order
  • The 50-event budget is re-checked between windows
  • A failing chunk does not abort its siblings
  • Single-chunk transcripts behave exactly as before

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions