Skip to content

Reduce GC churn in transcription worker (5026 GCs / 707ms in 30s) #112

Description

@ysdede

Trace: Trace-20260213T014231.json (summary in trace_analysis_summary.json)

Evidence

  • GC total: 6518 collections, 1006.4ms total
  • Dedicated worker TID 19820: 5026 GCs, 707.3ms total, max 10.1ms

Impact

  • Background worker spends significant time in GC, increasing tail latency for transcription and VAD.

Hypothesis

  • High-frequency allocation in worker pipelines (window building, result objects, typed arrays) during steady-state streaming.

Candidate locations

  • src/lib/transcription/transcription.worker.ts (per-window ASR result mapping + postMessage payloads)
  • src/lib/transcription/TokenStreamTranscriber.ts (per-chunk allocations and object spreads)
  • src/lib/audio/mel.worker.ts (new arrays in getFeatures)

Actions

  • Pool/reuse typed arrays and result objects; avoid per-chunk object literals where possible.
  • Use Transferables for large buffers to reduce cloning and associated allocations.
  • Add allocation counters or a simple performance.memory sampling in worker to validate.

Acceptance

  • Worker GC total time reduced by at least 50% in a 30s trace.
  • Fewer long GC pauses (>5ms) observed on worker 19820.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance optimization and profilingpriority:highImportant next work, impacts stability/performance/usability

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions