Spaces:
Sleeping
Sleeping
Tengo Gzirishvili Claude Opus 4.8 commited on
Commit ·
0c44e17
1
Parent(s): 3317015
perf: throttle + pause the living-logo animation (laptop fans)
Browse filesinitPlasmidLogo ran an UNTHROTTLED infinite requestAnimationFrame doing ~264
shadow-blurred canvas strokes per frame — at 60/120Hz that pegs a CPU core and
spins fans, and it never stopped (background tab, off-screen sidebar). Now:
- cap to ~30fps via a time accumulator (2-4x fewer expensive frames)
- pause entirely when the tab is hidden (visibilitychange) or the logo is
scrolled off-screen (IntersectionObserver)
- reduced-motion still draws one static frame
Verified in preview: draws << raw rAF when visible; 0 draws when off-screen.
Cache-buster -> v=20260607-perf.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- dee/static/app.js +27 -3
- dee/static/index.html +2 -2
dee/static/app.js
CHANGED
|
@@ -465,7 +465,7 @@ showRoute(currentRoute());
|
|
| 465 |
const readColor = () => { try { color = (getComputedStyle(document.documentElement).getPropertyValue('--accent') || '#1E3A8A').trim(); } catch (e) {} };
|
| 466 |
readColor();
|
| 467 |
try { new MutationObserver(readColor).observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] }); } catch (e) {}
|
| 468 |
-
function
|
| 469 |
ctx.setTransform(DPR, 0, 0, DPR, 0, 0);
|
| 470 |
// Choreographed morph — only ONE transformation at a time, so it
|
| 471 |
// never tangles: hold ring → STRETCH round→tall (no twist) → TWIST
|
|
@@ -497,9 +497,33 @@ showRoute(currentRoute());
|
|
| 497 |
ctx.shadowColor = color; ctx.shadowBlur = 3;
|
| 498 |
const strand = (P, sign) => { for (let i = 0; i < N; i++) { const d = sign * dep[i], f = (d + 1) / 2; ctx.strokeStyle = rgba(color, 0.5 + 0.5 * f); ctx.lineWidth = 1.5 + 0.8 * f; ctx.beginPath(); ctx.moveTo(P[i][0], P[i][1]); ctx.lineTo(P[i + 1][0], P[i + 1][1]); ctx.stroke(); } };
|
| 499 |
strand(B, -1); strand(A, 1); ctx.shadowBlur = 0;
|
| 500 |
-
if (!reduce) requestAnimationFrame(frame);
|
| 501 |
}
|
| 502 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
}
|
| 504 |
document.querySelectorAll('.brand-mark-canvas').forEach(mount);
|
| 505 |
})();
|
|
|
|
| 465 |
const readColor = () => { try { color = (getComputedStyle(document.documentElement).getPropertyValue('--accent') || '#1E3A8A').trim(); } catch (e) {} };
|
| 466 |
readColor();
|
| 467 |
try { new MutationObserver(readColor).observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] }); } catch (e) {}
|
| 468 |
+
function draw(now) {
|
| 469 |
ctx.setTransform(DPR, 0, 0, DPR, 0, 0);
|
| 470 |
// Choreographed morph — only ONE transformation at a time, so it
|
| 471 |
// never tangles: hold ring → STRETCH round→tall (no twist) → TWIST
|
|
|
|
| 497 |
ctx.shadowColor = color; ctx.shadowBlur = 3;
|
| 498 |
const strand = (P, sign) => { for (let i = 0; i < N; i++) { const d = sign * dep[i], f = (d + 1) / 2; ctx.strokeStyle = rgba(color, 0.5 + 0.5 * f); ctx.lineWidth = 1.5 + 0.8 * f; ctx.beginPath(); ctx.moveTo(P[i][0], P[i][1]); ctx.lineTo(P[i + 1][0], P[i + 1][1]); ctx.stroke(); } };
|
| 499 |
strand(B, -1); strand(A, 1); ctx.shadowBlur = 0;
|
|
|
|
| 500 |
}
|
| 501 |
+
// Perf: this was an UNTHROTTLED infinite rAF doing ~264 shadow-blurred
|
| 502 |
+
// strokes/frame — it pegs a CPU core and spins laptop fans. Cap to
|
| 503 |
+
// ~30fps and PAUSE entirely when the tab is hidden or the logo is
|
| 504 |
+
// scrolled off-screen. Reduced-motion → a single static frame.
|
| 505 |
+
let rafId = 0, running = false, inView = true, last = 0;
|
| 506 |
+
const FRAME_MS = 1000 / 30;
|
| 507 |
+
function loop(now) {
|
| 508 |
+
if (!running) return;
|
| 509 |
+
if (now - last >= FRAME_MS) { last = now; draw(now); }
|
| 510 |
+
rafId = requestAnimationFrame(loop);
|
| 511 |
+
}
|
| 512 |
+
function play() { if (running || reduce) return; running = true; last = 0; rafId = requestAnimationFrame(loop); }
|
| 513 |
+
function pause() { running = false; if (rafId) cancelAnimationFrame(rafId); rafId = 0; }
|
| 514 |
+
if (reduce) { draw(performance.now()); return; } // honor prefers-reduced-motion
|
| 515 |
+
document.addEventListener('visibilitychange', function () {
|
| 516 |
+
document.hidden ? pause() : (inView && play());
|
| 517 |
+
});
|
| 518 |
+
let hasIO = false;
|
| 519 |
+
try {
|
| 520 |
+
const io = new IntersectionObserver(function (es) {
|
| 521 |
+
inView = es[0].isIntersecting;
|
| 522 |
+
(inView && !document.hidden) ? play() : pause();
|
| 523 |
+
}, { threshold: 0 });
|
| 524 |
+
io.observe(cv); hasIO = true;
|
| 525 |
+
} catch (e) {}
|
| 526 |
+
if (!hasIO && !document.hidden) play(); // no IntersectionObserver → run (still capped + visibility-paused)
|
| 527 |
}
|
| 528 |
document.querySelectorAll('.brand-mark-canvas').forEach(mount);
|
| 529 |
})();
|
dee/static/index.html
CHANGED
|
@@ -22,7 +22,7 @@
|
|
| 22 |
<!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
|
| 23 |
app.js change. Bump these numbers whenever you ship a frontend update —
|
| 24 |
without them, users keep getting the stale file for up to a week. -->
|
| 25 |
-
<link rel="stylesheet" href="/static/app.css?v=20260607-
|
| 26 |
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
|
| 27 |
<link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
|
| 28 |
<!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
|
|
@@ -1669,6 +1669,6 @@
|
|
| 1669 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1670 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1671 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1672 |
-
<script src="/static/app.js?v=20260607-
|
| 1673 |
</body>
|
| 1674 |
</html>
|
|
|
|
| 22 |
<!-- ?v= query bumps invalidate browser + iframe asset caches when app.css /
|
| 23 |
app.js change. Bump these numbers whenever you ship a frontend update —
|
| 24 |
without them, users keep getting the stale file for up to a week. -->
|
| 25 |
+
<link rel="stylesheet" href="/static/app.css?v=20260607-perf" />
|
| 26 |
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg?v=2" />
|
| 27 |
<link rel="apple-touch-icon" href="/static/favicon.svg?v=2" />
|
| 28 |
<!-- Mol* (PDBe) viewer for AlphaFold structure embed. Loaded async; the
|
|
|
|
| 1669 |
<!-- Cloning reference data must load before app.js so the Designer
|
| 1670 |
can read VECTORS / ENZYMES / CLONING_METHODS / TAGS / LINKERS. -->
|
| 1671 |
<script src="/static/cloning_db.js?v=20260530-ui-polish" defer></script>
|
| 1672 |
+
<script src="/static/app.js?v=20260607-perf" defer></script>
|
| 1673 |
</body>
|
| 1674 |
</html>
|