Skip to content

Stop the working shimmer from repainting on the main thread every frame - #3906

Merged
SawyerHood merged 1 commit into
mainfrom
bb/reduce-background-cpu-load-thr_9ajmt8f4zh
Sep 18, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/reduce-background-cpu-load-thr_9ajmt8f4zh

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

With an agent working and the user doing nothing, the app kept roughly one CPU core busy. The cause is the working shimmer: .animate-shine animates background-position and .animate-shine-icon animates mask-position. The compositor cannot run either, so every frame at 60 fps is a full main-thread style, paint, layerize, and commit pass, and the cost of that pass grows with the weight of the page around the label.

A DevTools trace of an idle app with one working thread showed 804 main-thread frames in 13.6 s with about 1% of the time in JavaScript. Every frame repainted the same four nodes (two title spans, two status icons). By OS thread: renderer main 47% of a core, GPU 28%, browser 13%, compositor 8.5%, Viz 7%.

There is no single regressing commit. The text sweep dates from the initial commit, the icon mask from #86, and will-change: transform from #1880 measured neutral (52.6% vs 50.7%). What grew is the page: on a synthetic timeline the same animation costs 41%, 52%, and 76% of a core at 300, 2,500, and 8,000 rows. The sweep also kept costing CPU while hidden, which is what #768 worked around with animation-play-state.

What changed

The sweep is now an animated image used as a mask, with the same look.

  • apps/app/src/components/ui/shine-sweep.png: a 2.6 KB, 128x2 APNG whose alpha band (50% to 100% to 50%) travels left to right once a second. theme.css stretches it over the element with mask-size: 100% 100%. The mask carries alpha only, so one file serves every theme, label, and icon; the text stays real DOM text.
  • Chromium advances animated images on the compositor, so the page's main thread does no work for the shimmer, and a hidden mask is not drawn at all.
  • apps/app/scripts/generate-shine-sweep.mjs writes the APNG with no dependencies (pnpm --filter @bb/app generate:shine-sweep). The file stays under Vite's 4 KB inline limit, so production CSS embeds it as a data URI and no separate request is made.
  • .animate-shine and .animate-shine-icon share one rule; the shine and shine-mask keyframes are gone. Reduced motion and inert / aria-hidden hosts set mask-image: none.
  • ThreadStatusGlyph: removed the animation-duration: 1.5s override on the plugin status icon, which no longer has any effect.

Behavior differences from the CSS sweep:

  • Icons sweep once a second like labels, instead of on their own 2.6 s cycle, and their edge alpha is 0.5 instead of 0.45.
  • The sweep redraws 20 to 30 times a second instead of 60.
  • All shimmering elements share the image's clock, so they sweep in phase.
  • The cadence lives in the file, so animation-duration / animation-play-state no longer affect it.

No wire, CLI, config, or plugin API change. Plugins that use the classes get the new behavior from the host CSS.

How you verified

  • New tests in theme.test.ts (fail before, pass after): the shared mask rule and absence of a CSS animation, the reduced-motion and hidden-host rules, and the APNG itself (frame count matches its control chunk, loops forever, runs 1 s, under 4 KB).
  • pnpm exec turbo run test --filter=@bb/app -- src/components/ui/theme.test.ts src/components/sidebar/ThreadRow.test.tsx src/components/ui/height-transition.test.tsx src/components/ui/scroll-to-bottom-button.test.tsx: 127 tests pass.
  • pnpm exec turbo run typecheck lint --filter=@bb/app: pass, 0 lint errors.
  • Other readers of theme.css: pnpm exec turbo run test --filter=@bb/mobile (307 tests) and pnpm exec turbo run generate --filter=@bb/plugin-build pass.
  • pnpm exec turbo run build --filter=@bb/app: the PNG is inlined into the main CSS byte-for-byte, no separate asset is emitted, and check-bundle-budget.mjs passes.
  • Measured in headless Chromium (per-process CPU from /proc, frame and paint counts from a trace):
main-thread frames/s paints/s draws/s CPU (% of a core)
Ladle streaming story, before 60 240 60 13.3
Ladle streaming story, after 0 0 20 4.6
Synthetic 2,500-row page, before 60 300 60 53
Synthetic 2,500-row page, after 0 0 20 8 to 9
Same page, shimmer inside a collapsed container, before 60 60 0 32
Same page, shimmer inside a collapsed container, after 0 0 0 0.8 (idle)
  • Look: the mask frames use the same triangle profile as the CSS gradient, a side-by-side real-time capture of the Ladle stories shows the same sweep in Chromium, and the owner compared it with the old sweep on an iPhone.
  • Not verified: Firefox, and the CPU cost in WebKit (only the look was checked there).

🤖 Generated with Claude Code

AGENT GENERATED

While an agent works and the user does nothing, `.animate-shine` and
`.animate-shine-icon` animated `background-position` / `mask-position`.
The compositor cannot run either, so every frame at 60 fps was a full
main-thread style, paint, layerize, and commit pass whose cost grows with
the weight of the page around the label. A DevTools trace of an idle app
with one working thread showed 804 main-thread frames in 13.6 s with about
1% of the time in JavaScript: roughly one core across the renderer, GPU,
browser, and compositor for a status cue. The same sweep kept costing CPU
inside collapsed containers.

The sweep is now an animated image used as a mask. `shine-sweep.png` is a
128x2 APNG whose alpha band travels left to right once a second, stretched
over the label or glyph. Chromium advances animated images on the
compositor, so the page's main thread does nothing, and a hidden mask is
not drawn at all. The look is unchanged: the mask carries alpha only, so
one 2.6 KB file serves every theme, label, and icon, and it stays under
Vite's inline limit so production CSS embeds it.

- `apps/app/scripts/generate-shine-sweep.mjs` writes the APNG with no
  dependencies (`pnpm --filter @bb/app generate:shine-sweep`).
- Reduced motion and `inert` / `aria-hidden` hosts drop the mask.
- Icons now sweep once a second like labels instead of on a 2.6 s cycle.
- The plugin status icon's `animation-duration` override had no effect
  any more and is removed.

Co-Authored-By: Claude Code <[email protected]>
@SawyerHood
SawyerHood merged commit fd1b86a into main Sep 18, 2026
16 checks passed
@SawyerHood
SawyerHood deleted the bb/reduce-background-cpu-load-thr_9ajmt8f4zh branch September 18, 2026 16:05
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