Skip to content

Eliminate per-window allocations in ring buffer reads #123

Description

@ysdede

Context

  • RingBuffer.read() allocates a new Float32Array for every window/segment read.
  • v3/v2 and segment extraction call read() frequently (windowing + segment verification).

Evidence

  • src/lib/audio/RingBuffer.ts (read allocates)
  • src/lib/audio/AudioEngine.ts uses ringBuffer.read() in processWindowCallbacks and segment extraction.
  • src/App.tsx v2/v3 paths read full windows for transcription.

Impact

  • Per-window allocations increase GC pressure and CPU during capture.

Actions

  • Prefer readInto() with a reused buffer for window reads.
  • For window streaming, consider a SharedArrayBuffer ring to avoid copies.
  • Add metrics to compare allocation counts before/after.

Acceptance

  • Allocation rate during recording decreases (observed via Performance/Memory).
  • Worker GC time reduced in a 30s capture.

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