8000 perf(editor): cache waveform pyramid on open — 9.8s→10ms for longform by johannboehme · Pull Request #62 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

perf(editor) 8000 : cache waveform pyramid on open — 9.8s→10ms for longform - #62

Merged
johannboehme merged 1 commit into
mainfrom
worktree-editor-fast-load
Jun 20, 2026
Merged

johannboehme merged 1 commit into
mainfrom
worktree-editor-fast-load

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

Problem

Opening the editor sat on a blank "Loading editor…" screen far longer than the JS bundle or file IO could explain.

Root cause (measured on real jobs, not guessed)

The editor rebuilt the waveform peak-pyramid from a full audio decode on every open — it called buildPeakPyramidAsync directly and ignored the IDB pyramid cache that the sync step (jobs.ts:567) and Triage already populate/read. For a 16-minute long-form track that is ~9.8 s of blank screen, every single open.

Measured via CDP against real project data (963 s long-form job, foreground tab):

"Loading editor" clears interactive
before (every open) 9820 ms 9938 ms
after (cached) 10 ms 138 ms

A real-Chromium pipeline benchmark confirmed the per-sample compute (decode/pyramid/analysis/loudness) is sub-second even at 15 min — the cost was the per-open rebuild, not the math. The ~30 s I first observed externally was background-tab rAF throttling, not real load.

Changes

  • load-master-audio.ts (TDD, 7 tests) — cached-pyramid-first. The cached pyramid carries the true master-audio duration, so loadJob gets its duration without decoding a single sample. A cache miss decodes + builds once and persists it, so the next open is instant (self-healing for jobs synced before the pyramid cache existed).
  • Editor.tsx — wire the cache; the full decode now runs only in the background for the sidechain loudness envelope, off the critical path; cam-URL resolution parallelized (was a serial per-cam OPFS loop); per-phase load timing behind ?perf=1.
  • editor-load.bench.browser.test.ts — real-Chromium benchmark of the load pipeline.

Testing

  • vitest --project=unit: 1209 passed (incl. 7 new load-master-audio tests)
  • tsc --noEmit: clean
  • Before/after verified against real long-form project data.

Follow-up (not in this PR)

The background decode (~10 s CPU per open, non-blocking, only for the sidechain loudness envelope) could be eliminated by persisting the loudness envelope like the pyramid/analysis caches.

🤖 Generated with Claude Code

The editor rebuilt the waveform peak-pyramid from a full audio decode on
every open (it called buildPeakPyramidAsync directly, ignoring the IDB
cache the sync step and Triage already use). For a 16-min longform track
that is ~9.8s of blank "Loading editor…" — on every single open.

Measured on real jobs (963s longform), foreground tab:
  "Loading editor" clears:  9820ms → 10ms
  interactive:              9938ms → 138ms

- load-master-audio.ts (TDD, 7 tests): cached-pyramid-first. The cached
  pyramid carries the true master duration, so loadJob gets its duration
  with no decode. A cache miss decodes+builds once and persists, so the
  next open is instant (self-healing for pre-cache jobs).
- The full decode now only runs in the background, for the sidechain
  loudness envelope — off the "Loading editor" critical path.
- Cam-URL resolution parallelized (was a serial per-cam OPFS loop).
- Per-phase load timing behind ?perf=1.
- editor-load.bench.browser.test.ts: real-Chromium pipeline benchmark
  that confirmed decode/pyramid/analysis compute is sub-second — the cost
  was the per-open rebuild, not the math.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@johannboehme
johannboehme merged commit 3438311 into main Jun 20, 2026
1 check passed
@johannboehme
johannboehme deleted the worktree-editor-fast-load branch June 20, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0