Skip to content

feat(starry-night): draw the sky on canvas so its cost no longer grows with window size - #73

Open
Heyian wants to merge 11 commits into
spicetify:mainfrom
Heyian:perf/starry-night-canvas
Open

Heyian wants to merge 11 commits into
spicetify:mainfrom
Heyian:perf/starry-night-canvas

Conversation

@Heyian

@Heyian Heyian commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Starry Night created one <div> per 4000 px² of window, and about 1 in 5 of them ran a box-shadow animation. At 3840×1200 that is 1152 elements and ~100 style recalcs/s, and renderer memory kept growing. This PR replaces them with two canvases and moves the shooting stars to the Web Animations API.

 .starrynight-bg-container
-  div.starrynight-star × floor(area / 4000)        # CSS twinkle1–4 keyframes
-  span.shootingstar × 4                             # CSS `animate`, 1500px fixed path
+  canvas.starrynight-static                         # non-twinkling stars, redrawn only on resize/DPR/recolor
+  canvas.starrynight-twinkle                        # twinkling stars + glow sprite, ~20 batches/s, timer-driven
+  span.starrynight-sentinel                         # 1ms color transition → recolor on palette change
+  span.shootingstar × 4                             # element.animate(), path ends when the tail clears the screen
themes/starry-night/
├── logic.ts   # pure math: field, twinkle envelope, flight geometry, scaling, motion state
├── sky.ts     # renderer/controller, all browser APIs injected
├── mount.ts   # DOM discovery, listeners, bounded wait, dispose
└── mod.tsx    # passes real globals to mountSky; playbar sync unchanged

Behavior:

  • Star count is unchanged up to MAX_STARS = 1500, so very large windows get a slightly sparser sky.
  • Each twinkling star gets a random phase and a 4–6 s period, with the original glow shape (20% on, 20% fade, 40% off, 20% fade in) and a subtle dot dip.
  • Shooting stars relaunch as soon as they leave the screen. Only the first flight has the 0–6 s delay.
  • Animation pauses while the window is hidden. prefers-reduced-motion gives a still sky with no shooting stars.
  • Live sky switching still works without a reload.
  • Resizing re-lays out the field.

Evidence

Measured on Spotify 1.3.4 / Chrome 151 at 3840×1200, DPR 1, music playing: 60 s warm-up, then 15 s samples over 10 minutes. CPU: 100% = one core.

Before After
Renderer CPU ~116% ~18–20%
GPU process CPU ~85% ~14–15%
Style recalcs ~100/s, ~300 ms/s ~41–47/s, ~10–20 ms/s
Renderer RSS 1470 MB, rising ~410–560 MB, flat (+49 MB max over 10 min)
p95 frame interval 16.7 ms 8.4 ms

Visual comparison: the seven skies at 1280×1000, before (left) and after (right).

montage

Tests: scripts/starry-night-theme.test.mts, 51 cases under node --test + happy-dom, covering:

  • star count and the cap
  • envelope shape, and how it wraps around
  • launch split and exit-aware distance
  • DPR scaling and pixel snapping
  • one static draw per layout
  • batch rate cap, with one frame request per batch

and more.

Merge Danger

Blast Radius: theme-only

  • Look: stars are drawn instead of styled. Glow, colors and density were matched against before/after recordings of all seven skies. Windows larger than 6 MP get fewer stars than before.
  • Custom palettes: a palette that sets --spice-star/--spice-star-glow to something that isn't a valid CSS color (e.g. hex without #) loses the glow. A palette without these variables falls back to white.
  • Version: 0.1.6 → 0.2.0 (minor). Change the level if you prefer a patch.

@Heyian
Heyian marked this pull request as ready for review November 5, 2026 20:43

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — Canvas-sky rewrite of the Starry Night theme, replacing the per-star DOM field with two canvases plus WAAPI shooting stars.

  • Static and twinkle canvases — non-twinkling stars drawn once per layout; twinkling stars redrawn in timer-driven batches (~20/s) with one glow sprite per star size.
  • Pure-math core — star field, twinkle envelope, flight geometry, DPR scaling, and motion state isolated in logic.ts with injected randomness.
  • Lifecycle controller — sky.ts owns frames, timers, and canvases, with coalesced resize settle, DPR query re-arming, visibility and reduced-motion handling, and sentinel-driven recoloring.
  • Bounded mount — mount.ts gives up after 20 tries instead of hanging the loader, wires resize/visibility/DPR/palette listeners, and removes everything on dispose.
  • WAAPI shooting stars — exit-aware flight distance with tail clearance, delay on first flight only, pause/resume on visibility, hidden under reduced motion.
  • Tests — 51 cases covering counts, envelope shape, geometry, DPR snapping, batch rate, lifecycle, and disposal; all pass and fmt:check is clean.

Pullfrog  | View workflow run | Using muse-spark-1.3-contributor (free via Pullfrog for OSS) | 𝕏

This branch has not been deployed

No deployments
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