perf(highway): held-sustain glow without shadowBlur (Mac stutter fix)#729
Conversation
shadowBlur cost scales with the blurred device-pixel area. The lit-sustain trail can span half the canvas, the canvas is DPR-scaled (4x pixels on a 2x Mac), and the blur ran on every frame exactly while a sustain is HELD — i.e. at the moment the player most notices a hitch. Sustain-heavy songs (e.g. fingerpicked acoustic charts) hit this constantly. Replace the blur with three inflated low-alpha fills of the same trail quad: reads as the same soft shimmering glow (the shimmer LUT still drives per-frame flicker, feedBack#254 intent preserved) at a flat, area-independent cost. Also drops the now-dead shadowBlur reset in the crackle pass; no shadowBlur uses remain in highway.js. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe glow rendering for held sustain trails in drawSustains was changed from a single shadowBlur-based fill to multiple fills of the same trail quad at varying inflation sizes and globalAlpha values derived from shimmer noise. The subsequent crackling current stroke logic remains unchanged. ChangesSustain Glow Rendering
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
static/highway.js (1)
2017-2030: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winAvoid allocating
fillTrailper note per frame in the hot path.
fillTrailis a fresh arrow-function closure created for every lit sustain on every animation frame — exactly the kind of per-frame allocation this PR (and the rest of the file, e.g._bundleReused,_shimmerLut, the stable-reference comment on_noteState) otherwise takes care to avoid. Hoisting it to a top-level helper (same pattern asroundRect) that accepts the geometry as parameters removes the closure allocation without changing behavior.♻️ Proposed refactor
+ // Fills the sustain-trail quad inflated by `inflate` px on each side — + // shared by all three glow-layer passes in drawSustains. Top-level + // (not a per-call closure) so it isn't reallocated per lit sustain + // per frame. + function fillSustainTrail(x0, y0, x1, y1, sw0, sw1, inflate) { + ctx.beginPath(); + ctx.moveTo(x0 - sw0 - inflate, y0); + ctx.lineTo(x0 + sw0 + inflate, y0); + ctx.lineTo(x1 + sw1 + inflate, y1); + ctx.lineTo(x1 - sw1 - inflate, y1); + ctx.fill(); + } + function drawSustains(W, H) { ... - const fillTrail = (inflate) => { - ctx.beginPath(); - ctx.moveTo(x0 - sw0 - inflate, y0); - ctx.lineTo(x0 + sw0 + inflate, y0); - ctx.lineTo(x1 + sw1 + inflate, y1); - ctx.lineTo(x1 - sw1 - inflate, y1); - ctx.fill(); - }; ctx.globalAlpha = baseA * 0.22; - fillTrail(glowPx); + fillSustainTrail(x0, y0, x1, y1, sw0, sw1, glowPx); ctx.globalAlpha = baseA * 0.4; - fillTrail(glowPx * 0.45); + fillSustainTrail(x0, y0, x1, y1, sw0, sw1, glowPx * 0.45); ctx.globalAlpha = baseA; - fillTrail(0); + fillSustainTrail(x0, y0, x1, y1, sw0, sw1, 0);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@static/highway.js` around lines 2017 - 2030, The per-frame `fillTrail` arrow function inside the sustain rendering hot path is creating a new closure for every lit note, which should be avoided. Hoist `fillTrail` out to a reusable helper in the same style as `roundRect`, and pass the geometry and context values it needs as parameters so the existing drawing calls in this sustain-rendering block can reuse it without changing behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@static/highway.js`:
- Around line 2017-2030: The per-frame `fillTrail` arrow function inside the
sustain rendering hot path is creating a new closure for every lit note, which
should be avoided. Hoist `fillTrail` out to a reusable helper in the same style
as `roundRect`, and pass the geometry and context values it needs as parameters
so the existing drawing calls in this sustain-rendering block can reuse it
without changing behavior.
Problem
User report: frequent hitches while playing on macOS, worst during held notes.
drawSustainssetctx.shadowBlurper lit trail per frame. Blur cost scales with the blurred device-pixel area — the trail can span half the canvas and the canvas is DPR-scaled (4× pixels on a 2× Mac), so this was a large per-frame raster pass that runs exactly while a sustain is held.Fix
Three inflated low-alpha fills of the same trail quad instead of the blur — same soft shimmering glow (the shimmer LUT still drives the per-frame flicker, feedBack#254 intent preserved), flat cost independent of trail size. No
shadowBluruses remain inhighway.js.Testing
node --checkclean.🤖 Generated with Claude Code
Summary by CodeRabbit