Commit 2bdd602
perf(web): cut click-handler latency from ~1s to ~0ms in PreviewPanel
"[Violation] click handler took 1151ms" — every state change to
ComposePage re-ran PreviewPanel's offline-render effect, which spun up
a fresh OfflineAudioContext (44.1 kHz × 10 s = 441k samples) and
synchronously walked every step's factory. With the click landing
inside the same task, the user-visible click→playback latency was
hundreds of ms.
PreviewPanel:
- Skip the offline render entirely while playback is active. The
on-screen waveform from the previous render stays visible; the
effect re-runs once when `playing` flips back to false.
- Cut sample rate from 44100 → 22050 (the preview is a visual
waveform, not an audible source) and cap the buffer length to 8 s.
~4× cheaper buffer alloc + render.
- Push the actual rendering through requestIdleCallback (250 ms
debounce, 400 ms timeout fallback). The click handler returns
immediately; the heavy work runs in the next idle slot.
- New `playing` dep on the render effect so the waveform refreshes the
moment playback ends.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent cd8792a commit 2bdd602
1 file changed
Lines changed: 26 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
84 | 89 | | |
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
88 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
89 | 100 | | |
90 | | - | |
91 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
92 | 109 | | |
93 | 110 | | |
94 | 111 | | |
| |||
109 | 126 | | |
110 | 127 | | |
111 | 128 | | |
112 | | - | |
113 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
114 | 135 | | |
115 | 136 | | |
116 | 137 | | |
| |||
256 | 277 | | |
257 | 278 | | |
258 | 279 | | |
259 | | - | |
| 280 | + | |
260 | 281 | | |
261 | 282 | | |
262 | 283 | | |
| |||
0 commit comments