Skip to content

Avoid repeated mel normalization/copy for overlapping windows #125

@ysdede

Description

@ysdede

Context

  • getFeatures() allocates a raw window buffer and then normalizes into a second buffer for every request.
  • v3/v4 request overlapping windows, so most frames are re-normalized repeatedly.

Evidence

  • src/lib/audio/mel.worker.tsgetFeatures copies into raw then normalizeMelFeatures() allocates out.
  • src/lib/audio/mel-math.tsnormalizeMelFeatures allocates a new Float32Array per call.

Impact

  • Extra allocations + CPU in feature extraction under continuous streaming.

Actions

  • Cache normalized frames per mel-bin in the circular buffer, or normalize in-place when raw is no longer needed.
  • For overlapping windows, reuse cached normalized frames and only normalize new frames.
  • Add a small LRU cache of recent getFeatures windows keyed by (start,end,normalize).

Acceptance

  • Feature extraction CPU time drops (p95) in a 30s capture.
  • Worker GC time reduced vs baseline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestperformancePerformance 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