Skip to content

Perf: lazy-load Inspector + CommandPalette, swap setInterval for rAF - #176

Merged
pablostanley merged 1 commit into
mainfrom
perf/dynamic-imports-raf
May 16, 2026
Merged

Perf: lazy-load Inspector + CommandPalette, swap setInterval for rAF#176
pablostanley merged 1 commit into
mainfrom
perf/dynamic-imports-raf

Conversation

@pablostanley

Copy link
Copy Markdown
Owner

Summary

Three low-hanging perf wins.

  • Lazy Inspector (FX panel) — was imported at the top of creator.tsx; pulled react-colorful into the main bundle even for visitors who never open FX. next/dynamic({ ssr: false }) puts it in its own ~16KB chunk fetched on first FX toggle.
  • Lazy CommandPalette — mounted in root layout so every page paid for it. Also next/dynamic now.
  • rAF for canvas animation loopsetInterval(FRAME_MS) kept firing on hidden tabs (battery drain) and wasn't vsync-aligned. Switched to requestAnimationFrame with a FRAME_MS throttle inside the step callback — same 72ms tick, auto-pauses when tab is hidden.

Build verified: react-colorful chunk is now a separate split.

Test plan

  • Creator loads, animates as before.
  • FX button opens Inspector; color picker renders (network panel shows new chunk fetched on first click).
  • ⌘K opens command palette; chunk fetched lazily.
  • Switch to another tab → return — animation resumes without piling up dropped frames.
  • prefers-reduced-motion still freezes to static frame.

🤖 Generated with Claude Code

Three small wins in the creator hot path:

1. Inspector (FX panel) was imported at the top of creator.tsx. It pulls
   react-colorful (~16KB chunk after split). Most visitors never open it.
   Now loaded via `next/dynamic` with ssr:false — separate chunk, fetched
   only when the FX button is clicked.

2. CommandPalette was mounted in the root layout, so every page paid for
   its bundle even though it's only used on ⌘K. Also `next/dynamic` now.

3. Creator's animation loop used `setInterval(FRAME_MS)`. That keeps
   firing on hidden tabs (battery drain) and isn't vsync-aligned. Swapped
   for `requestAnimationFrame` with a FRAME_MS throttle inside the step
   callback — same 72ms tick cadence, auto-pauses when tab is hidden.

Build verified: Inspector + react-colorful land in their own chunk
(16.4KB) instead of the main creator bundle.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented May 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pixabots Ready Ready Preview, Comment May 16, 2026 4:20pm

Request Review

@pablostanley
pablostanley merged commit 8973c8d into main May 16, 2026
3 checks passed
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