Skip to content

perf(dashboard): bring back dial animations without the 20% CPU cost - #17

Merged
WolffTech merged 1 commit into
mainfrom
feat/efficient-dial-animation
Nov 3, 2026
Merged

WolffTech merged 1 commit into
mainfrom
feat/efficient-dial-animation

Conversation

@WolffTech

Copy link
Copy Markdown
Owner

The instrument cluster's dials used to sweep to each new reading, but that animation was removed in #6 because SwiftUI re-rendered the whole dashboard on every frame, costing about 20% CPU while the panel was open. Since then the needles have jumped from value to value.

The dials animate again, now in Core Animation. The fill arc, needle, and hub are shape layers: the arc is a full-sweep path trimmed with strokeEnd, and the needle is drawn at zero and rotated about the hub. Each reading hands the render server two spring animations (matching SwiftUI's .smooth), so SwiftUI does no work between frames and no path is rebuilt. The track and ticks stay SwiftUI shapes.

  • The first reading after the panel opens appears in place without sweeping from zero.
  • With Reduce Motion on, the dials jump to each reading as before.
  • Clicks and hovers still go to the tile, so dials still open their details.

Testing

Proved by measuring and recording the running Release build.

  • CPU with the cluster panel open, Release build, sampled with top: about 3% before (static dials), about 18–21% with the old SwiftUI animation restored, about 3% with this change.
  • Screen recordings show the needle and arc sweeping between readings, including holding steady at 100% under full CPU load and sweeping back the short way from 94% to 6%.
  • Clicking a dial opens its details panel.
  • Switching the app's appearance from dark to light while open recolors the needle and hub.
  • swift test in Packages/BarometryKit passes.

- Move the dial fill, needle, and hub into CAShapeLayers so the render
  server animates new readings without re-rendering SwiftUI
- Trim a full-sweep arc with strokeEnd and rotate the needle about
  the hub, so no path is rebuilt per frame
- Match SwiftUI's .smooth spring and skip animation for Reduce Motion
@WolffTech
WolffTech merged commit 02f3b68 into main Nov 3, 2026
2 checks passed
@WolffTech
WolffTech deleted the feat/efficient-dial-animation branch November 10, 2026 20:23
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