Skip to content

Apps: smoother prediction animation#797

Merged
microbit-matt-hillsdon merged 7 commits intoappsfrom
apps-smoother-prediction-animation
Mar 18, 2026
Merged

Apps: smoother prediction animation#797
microbit-matt-hillsdon merged 7 commits intoappsfrom
apps-smoother-prediction-animation

Conversation

@glastonbridge
Copy link
Collaborator

Addresses #700

When running prediction, CreateAI can be glitchy on slower devices as the prediction step runs every 250ms triggering a redraw of parts of the React tree. Most of the processing delay is taken up not with processing, but with updating in React, which is not really intended for responsive animation.

The fix

The LedIcon and ActionNameCard have colour changes when they become the detected action, these are now subscribed to outside of react and the HTML elements modified directly. The PercentageDisplay, PercentageMeter, ActionCertaintyCard have their data updated similarly. The LedIcon in PredictedAction changes the actual icon data inside its LedIcon, so it would be more intrusive to move entirely outside of the React update tree, so there is still some slowdown when the predicted action changes. However, it happens much less often.

Performance before fix

Performance data was collected in a web browser with CPU throttling at 20x on an M1 Macbook. Both sample screenshots show around 2s of data.

Screenshot 2026-03-17 at 13 36 18

Performance after fix

This shows shorter updates happening more regularly, which corresponds to a smoother UI.

Screenshot 2026-03-17 at 13 45 21

@github-actions
Copy link

@glastonbridge glastonbridge marked this pull request as ready for review March 17, 2026 15:23
glastonbridge and others added 4 commits March 17, 2026 16:53
Replace CSS variable names (without var, so just nonsense colours) with
useToken. This gets us the green back on the percentage.

Simplfy LedIcon and move the subscription to the place where it matters.
Add initiallyOn prop to LedIcon so the CSS variable is correct from
the first paint, removing the need for an eager getState() call in
ActionNameCard. Add missing displayName for forwardRef lint rule.
Remove stale comment in PercentageMeter.
Copy link

@microbit-grace microbit-grace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested out on iOS and the experience is observably better (less jerky graphlines) in the testing model page than before.

@microbit-matt-hillsdon microbit-matt-hillsdon changed the title Apps smoother prediction animation Apps: smoother prediction animation Mar 18, 2026
@microbit-matt-hillsdon microbit-matt-hillsdon merged commit 8b591ae into apps Mar 18, 2026
3 checks passed
@microbit-matt-hillsdon microbit-matt-hillsdon deleted the apps-smoother-prediction-animation branch March 18, 2026 17:25
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.

3 participants