Skip to content

Optimize DebugPanel drawing/painting (spectrogram + waveform) #116

@ysdede

Description

@ysdede

Context

  • LayeredBufferVisualizer runs a continuous rAF loop (~30fps) and draws a full spectrogram using putImageData every 100ms.
  • drawSpectrogramToCanvas touches every pixel (width * height), then uploads to canvas each time.

Evidence

  • File: src/components/LayeredBufferVisualizer.tsx (loop + putImageData + per-frame waveform draw)
  • Frame jank present in trace (max interval 80.1ms).

Hypothesis

  • DebugPanel open increases paint time and GC due to large ImageData uploads and per-frame waveform sampling.

Actions

  • Only redraw spectrogram when new features are available; skip putImageData if unchanged.
  • Reduce resolution (downsample width/height) or render to OffscreenCanvas + ImageBitmap transfer.
  • Pause the loop when not recording or when panel is not visible.

Acceptance

  • With DebugPanel open, no additional long tasks >50ms vs panel closed.
  • CPU time for DebugPanel rendering reduced by at least 30%.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestperformancePerformance optimization and profiling

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions