Repository navigation
perf(dashboard): bring back dial animations without the 20% CPU cost - #17
Merged
Merged
Conversation
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Testing
Proved by measuring and recording the running Release build.
top: about 3% before (static dials), about 18–21% with the old SwiftUI animation restored, about 3% with this change.swift testinPackages/BarometryKitpasses.