Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Quantize always-running indicator animations to cut per-frame commits

justrach4f270269bd76
diff --git a/apps/native/app/globals.css b/apps/native/app/globals.css
index c79556dc..ae65e756 100644
--- a/apps/native/app/globals.css
+++ b/apps/native/app/globals.css
@@ -926,7 +926,7 @@ th.is-colsel .records-header-icon {
flex: 0 0 8px;
border-radius: 50%;
background: var(--accent);
- animation: records-pulse 1.1s ease-in-out infinite;
+ animation: records-pulse 1.1s steps(6, end) infinite;
}
@keyframes records-pulse {
diff --git a/apps/native/app/motion.css b/apps/native/app/motion.css
index 5a8c9724..2a25cd01 100644
--- a/apps/native/app/motion.css
+++ b/apps/native/app/motion.css
@@ -12,6 +12,13 @@
50% { opacity: 0.6; }
}
+/* Ambient, infinitely-running indicators are quantized with steps() at
+ * their call sites: a value that only changes a few times per second
+ * avoids a full-window compositor commit on every animation frame, which
+ * otherwise holds several percent of CPU for the duration of a turn
+ * (#1037). New infinite animations must do the same;
+ * lib/motion-throttle.test.ts enforces it. */
+
@keyframes fade-up {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: none; }
diff --git a/apps/native/components/atoms/Shimmer.tsx b/apps/native/components/atoms/Shimmer.tsx
index 4bc88f4a..a61960ea 100644
--- a/apps/native/components/atoms/Shimmer.tsx
+++ b/apps/native/components/atoms/Shimmer.tsx
@@ -13,7 +13,7 @@ export function Shimmer({
backgroundImage:
"linear-gradient(90deg, var(--ink-3) 35%, var(--ink) 50%, var(--ink-3) 65%)",
backgroundSize: "200% 100%",
- animation: "shimmer-text 1.8s linear infinite",
+ animation: "shimmer-text 1.8s steps(8, end) infinite",
}}
>
{children}
diff --git a/apps/native/components/primitives/FineTuneCard.tsx b/apps/native/components/primitives/FineTuneCard.tsx
index 400268d5..9091d889 100644
--- a/apps/native/components/primitives/FineTuneCard.tsx
+++ b/apps/native/components/primitives/FineTuneCard.tsx
@@ -142,7 +142,7 @@ export default function FineTuneCard() {
backgroundImage:
"linear-gradient(90deg, var(--accent) 35%, var(--accent-ink) 50%, var(--accent) 65%)",
backgroundSize: "200% 100%",
- animation: "shimmer-text 1.4s linear infinite",
+ animation: "shimmer-text 1.4s steps(8, end) infinite",
}}
>
Adjust
diff --git a/apps/native/components/primitives/LoadingState.tsx b/apps/native/components/primitives/LoadingState.tsx
index 06b196c5..5e3c8fc0 100644
--- a/apps/native/components/primitives/LoadingState.tsx
+++ b/apps/native/components/primitives/LoadingState.tsx
@@ -52,7 +52,7 @@ function LoaderGrid({
className={`size-[4px] bg-ink ${round ? "rounded-full" : "rounded-[1px]"}`}
style={{
opacity: delay === null ? 0.07 : 0.15,
- animation: delay === null ? "none" : `pixel-on ${dur}ms ease-in-out ${delay}ms infinite`,
+ animation: delay === null ? "none" : `pixel-on ${dur}ms steps(4, end) ${delay}ms infinite`,
}}
/>
))}
@@ -99,7 +99,7 @@ export default function LoadingState({
backgroundImage:
"linear-gradient(90deg, var(--ink-3) 35%, var(--ink) 50%, var(--ink-3) 65%)",
backgroundSize: "200% 100%",
- animation: "shimmer-text 1.4s linear infinite",
+ animation: "shimmer-text 1.4s steps(8, end) infinite",
}}
>
{resolvedLabel}
diff --git a/apps/native/components/primitives/PromptBar.tsx b/apps/native/components/primitives/PromptBar.tsx
index 20ae24f6..be7eaeb1 100644
--- a/apps/native/components/primitives/PromptBar.tsx
+++ b/apps/native/components/primitives/PromptBar.tsx
@@ -536,7 +536,7 @@ export default function PromptBar({
<span
key={i}
className="w-[2.5px] rounded-full bg-current"
- style={{ height: "100%", animation: `eq-bounce 900ms ease-in-out ${i * 150}ms infinite` }}
+ style={{ height: "100%", animation: `eq-bounce 900ms steps(6, end) ${i * 150}ms infinite` }}
/>
))}
</span>
diff --git a/apps/native/components/primitives/SelectionActions.tsx b/apps/native/components/primitives/SelectionActions.tsx
index 99fa3ad6..0f1de2a4 100644
--- a/apps/native/components/primitives/SelectionActions.tsx
+++ b/apps/native/components/primitives/SelectionActions.tsx
@@ -293,7 +293,7 @@ export default function SelectionActions() {
<span className="inline-flex h-7 items-center gap-1.5 whitespace-nowrap px-2.5 text-[12.5px] font-normal text-ink-2">
<span
className="size-3 shrink-0 rounded-full border-[1.5px] border-line-strong border-t-ink-2"
- style={{ animation: "spin 700ms linear infinite" }}
+ style={{ animation: "spin 700ms steps(16, end) infinite" }}
/>
{mode === "thinking" ? (
<Shimmer className="text-[12.5px] font-normal">
diff --git a/apps/native/components/primitives/TaskRows.tsx b/apps/native/components/primitives/TaskRows.tsx
index 1073c2b5..d2257dcd 100644
--- a/apps/native/components/primitives/TaskRows.tsx
+++ b/apps/native/components/primitives/TaskRows.tsx
@@ -33,7 +33,7 @@ function SpinnerRing({ active, children }: { active?: boolean; children?: React.
<span className="relative inline-flex shrink-0 items-center justify-center" style={{ width: size, height: size }}>
<svg
width={size} height={size} className="absolute inset-0"
- style={active ? { animation: "spin 1.1s linear infinite" } : undefined}
+ style={active ? { animation: "spin 1.1s steps(16, end) infinite" } : undefined}
>
<circle cx={size / 2} cy={size / 2} r={r} fill="none" stroke="var(--line)" strokeWidth={stroke} />
{active && (
@@ -166,7 +166,7 @@ export default function TaskRows({
pill:
row2 === "failed" ? (
<span className="inline-flex h-5.5 items-center gap-1.5 rounded-full bg-red-tint px-2 text-[11.5px] font-medium text-red" style={{ animation: "fade-in 200ms ease-out both" }}>
- Failed <span style={{ animation: "spin 1.2s linear infinite" }} className="flex">{RetryIcon}</span>
+ Failed <span style={{ animation: "spin 1.2s steps(16, end) infinite" }} className="flex">{RetryIcon}</span>
</span>
) : row2 === "done" ? (
<span className="inline-flex h-5.5 items-center gap-1.5 rounded-full bg-green-tint px-2 text-[11.5px] font-medium text-green" style={{ animation: "fade-in 200ms ease-out both" }}>
diff --git a/apps/native/components/primitives/ThinkingState.tsx b/apps/native/components/primitives/ThinkingState.tsx
index 0936053f..b3be0982 100644
--- a/apps/native/components/primitives/ThinkingState.tsx
+++ b/apps/native/components/primitives/ThinkingState.tsx
@@ -198,7 +198,7 @@ export default function ThinkingState({
backgroundImage:
"linear-gradient(90deg, var(--ink-3) 35%, var(--ink) 50%, var(--ink-3) 65%)",
backgroundSize: "200% 100%",
- animation: "shimmer-text 1.4s linear infinite",
+ animation: "shimmer-text 1.4s steps(8, end) infinite",
}}
>
{v.active}
@@ -257,21 +257,21 @@ export default function ThinkingState({
<path d="M20 6L9 17l-5-5" />
</svg>
) : (
- <span className="size-3 shrink-0 rounded-full border-[1.5px] border-line-strong border-t-ink-2" style={{ animation: expanded ? "spin 700ms linear infinite" : undefined }} />
+ <span className="size-3 shrink-0 rounded-full border-[1.5px] border-line-strong border-t-ink-2" style={{ animation: expanded ? "spin 700ms steps(16, end) infinite" : undefined }} />
)
)}
{row.shimmer ? (
<>
<span
className="size-3 shrink-0 rounded-full border-[1.5px] border-line-strong border-t-ink-2"
- style={{ animation: working && expanded ? "spin 700ms linear infinite" : undefined }}
+ style={{ animation: working && expanded ? "spin 700ms steps(16, end) infinite" : undefined }}
/>
<span
className="min-w-0 truncate bg-clip-text text-[12.5px] leading-relaxed text-transparent"
style={{
backgroundImage: "linear-gradient(90deg, var(--ink-3) 35%, var(--ink) 50%, var(--ink-3) 65%)",
backgroundSize: "200% 100%",
- animation: working && expanded ? "shimmer-text 1.4s linear infinite" : undefined,
+ animation: working && expanded ? "shimmer-text 1.4s steps(8, end) infinite" : undefined,
}}
>
{row.primary}
diff --git a/apps/native/components/primitives/ToolChips.tsx b/apps/native/components/primitives/ToolChips.tsx
index 9819d955..147dfdab 100644
--- a/apps/native/components/primitives/ToolChips.tsx
+++ b/apps/native/components/primitives/ToolChips.tsx
@@ -249,7 +249,7 @@ export default function ToolChips({
{"status" in row && row.status === "running" ? (
<span
className={`size-3 rounded-full border-[1.5px] border-line-strong border-t-ink-2 transition-opacity duration-100 group-hover/row:opacity-0 ${rowOpen ? "opacity-0" : ""}`}
- style={{ animation: "spin 700ms linear infinite" }}
+ style={{ animation: "spin 700ms steps(16, end) infinite" }}
/>
) : (
<svg
diff --git a/apps/native/lib/motion-throttle.test.ts b/apps/native/lib/motion-throttle.test.ts
new file mode 100644
index 00000000..2b9efd8d
--- /dev/null
+++ b/apps/native/lib/motion-throttle.test.ts
@@ -0,0 +1,52 @@
+import { describe, it } from "node:test";
+import assert from "node:assert/strict";
+import { readdirSync, readFileSync, statSync } from "node:fs";
+import { fileURLToPath } from "node:url";
+import { join } from "node:path";
+
+const root = fileURLToPath(new URL("../", import.meta.url));
+
+// Every infinitely-running animation must quantize its timing with steps()
+// (or step-end). A value that only changes a few times per second avoids a
+// full-window compositor commit on every animation frame; unquantized
+// infinite animations hold several percent of CPU for as long as they are
+// mounted. See #1037 and the policy comment in app/motion.css.
+function* scan(dir: string): Generator<string> {
+ for (const entry of readdirSync(dir)) {
+ const path = join(dir, entry);
+ if (statSync(path).isDirectory()) yield* scan(path);
+ else if (/\.(tsx|css)$/.test(entry) && !entry.includes(".test.")) yield path;
+ }
+}
+
+function cssBody(path: string): string {
+ // Strip comments so prose mentioning the policy does not read as a declaration.
+ return readFileSync(path, "utf8").replace(/\/\*[\s\S]*?\*\//g, "");
+}
+
+function unquantized(line: string): boolean {
+ return /\binfinite\b/.test(line) && !/\bsteps?\(/.test(line) && !/\bstep-(?:start|end)\b/.test(line);
+}
+
+describe("motion throttle", () => {
+ it("quantizes every infinite animation", () => {
+ const offenders: string[] = [];
+ for (const dir of ["components", "app"]) {
+ for (const path of scan(join(root, dir))) {
+ const source = path.endsWith(".css") ? cssBody(path) : readFileSync(path, "utf8");
+ source.split("\n").forEach((line, i) => {
+ if (unquantized(line)) {
+ offenders.push(`${path}:${i + 1}: ${line.trim()}`);
+ }
+ });
+ }
+ }
+ assert.deepEqual(offenders, []);
+ });
+
+ it("keeps the global prefers-reduced-motion override", () => {
+ const motion = readFileSync(join(root, "app", "motion.css"), "utf8");
+ assert.match(motion, /@media \(prefers-reduced-motion: reduce\)/);
+ assert.match(motion, /animation-iteration-count: 1 !important/);
+ });
+});
diff --git a/apps/native/package.json b/apps/native/package.json
index 7a0a7e37..275d5448 100644
--- a/apps/native/package.json
+++ b/apps/native/package.json
@@ -10,7 +10,7 @@
"start": "NEXT_TELEMETRY_DISABLED=1 next start --port 3000",
"mock-serve": "node scripts/mock-serve.mjs",
"lint": "next lint",
- "test": "node --experimental-strip-types --test lib/cite-markup.test.ts lib/graff-events.test.ts lib/acp.test.ts lib/sessions.test.ts lib/session-store.test.ts lib/follow-scroll.test.ts lib/prompt-queue.test.ts lib/prompt-queue-steer.test.ts lib/prompt-queue-resume.test.ts lib/streaming-code.test.ts lib/agents.test.ts lib/mermaid-plugin.test.ts lib/prompt-history.test.ts lib/attachments.test.ts lib/workspaces.test.ts lib/fuzzy.test.ts lib/folder-picker.test.ts lib/browser/annotations.test.ts lib/browser/url.test.ts lib/extension-bridge.test.ts components/site/harness-split.test.ts components/site/appearance-panel.test.ts",
+ "test": "node --experimental-strip-types --test lib/cite-markup.test.ts lib/graff-events.test.ts lib/acp.test.ts lib/sessions.test.ts lib/session-store.test.ts lib/follow-scroll.test.ts lib/motion-throttle.test.ts lib/prompt-queue.test.ts lib/prompt-queue-steer.test.ts lib/prompt-queue-resume.test.ts lib/streaming-code.test.ts lib/agents.test.ts lib/mermaid-plugin.test.ts lib/prompt-history.test.ts lib/attachments.test.ts lib/workspaces.test.ts lib/fuzzy.test.ts lib/folder-picker.test.ts lib/browser/annotations.test.ts lib/browser/url.test.ts lib/extension-bridge.test.ts components/site/harness-split.test.ts components/site/appearance-panel.test.ts",
"electron:build": "bash electron/build.sh",
"test:electron": "bun test electron/policy.test.cjs",
"test:webauthn": "node scripts/test-webauthn.mjs",