-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throttle events in polygon #1444
Conversation
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (e41b7e0) and published it to npm. You Example: yarn add @khanacademy/perseus@PR1444 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR1444 |
Size Change: +860 B (+0.1%) Total Size: 855 kB
ℹ️ View Unchanged
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1444 +/- ##
==========================================
+ Coverage 69.86% 70.26% +0.40%
==========================================
Files 505 508 +3
Lines 105665 105672 +7
Branches 7670 10801 +3131
==========================================
+ Hits 73826 74254 +428
+ Misses 31659 31418 -241
+ Partials 180 0 -180
... and 166 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
@@ -42,6 +42,7 @@ export const PolygonGraph = (props: Props) => { | |||
}); | |||
|
|||
const active = hovered || focused || dragging; | |||
const [lastMoveTime, setLastMoveTime] = React.useState<number>(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this optimization work!
Could we use a ref instead of state here? That would prevent unnecessary re-renders. I believe a ref is appropriate because we will never need to update DOM elements when lastMoveTime
changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yepppppp. You're absolutely right. Fixed up
} | ||
onMove={(destination: vec.Vector2) => { | ||
const now = Date.now(); | ||
const targetFPS = 40; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale for capping FPS at 40? For displays that refresh at 60Hz (or browsers that repaint at 60Hz?), this will result in every third frame getting dropped. I guess my question is, why not 30 fps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loosely held opinion: 40 fps feels about right. I've noticed in games it's where things start to feel smooth (which is totally subjective). Some data, though: If I cap at 40fps I get around 26% CPU usage. If I cap at 60 I get around 40%.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 LGTM!
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @khanacademy/[email protected] ### Major Changes - [#1456](#1456) [`b868801fa`](b868801) Thanks [@benchristel](https://github.com/benchristel)! - Remove unused "Show ruler" option from the interactive graph editor. The new Mafs version of the interactive graph does not implement the ruler, and we have no plans to implement it, since it can't be made accessible and isn't used in Khan Academy's existing content. - [#1450](#1450) [`2216ad012`](2216ad0) Thanks [@handeyeco](https://github.com/handeyeco)! - Remove Unit aka UnitInput widget ### Minor Changes - [#1451](#1451) [`9bc4812fc`](9bc4812) Thanks [@mark-fitzgerald](https://github.com/mark-fitzgerald)! - Upgrade Mafs Dependency to v0.19.0 for Domain Restricted Functions - [#1441](#1441) [`9bc264ce1`](9bc264c) Thanks [@Myranae](https://github.com/Myranae)! - Turn off interactivity when Interactive Graph in hint mode - [#1437](#1437) [`7a448e77c`](7a448e7) Thanks [@Myranae](https://github.com/Myranae)! - Update Polygon to be filled on hover - [#1422](#1422) [`c386515ad`](c386515) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph Editor] Segment and Linear System graph start coords UI ### Patch Changes - [#1448](#1448) [`84675574c`](8467557) Thanks [@nishasy](https://github.com/nishasy)! - Cleaned up the `startCoords` code in the stateful mafs graph useEffect - [#1444](#1444) [`130ab9446`](130ab94) Thanks [@nicolecomputer](https://github.com/nicolecomputer)! - Throttles point-moving performance in polygon - [#1445](#1445) [`bb1ac584b`](bb1ac58) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - useDraggable - fix to ignore keyup events (we don't want to treat keyup events as an intent to move - we have keydown for that) - Updated dependencies \[[`7e71f8e8a`](7e71f8e)]: - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Major Changes - [#1456](#1456) [`b868801fa`](b868801) Thanks [@benchristel](https://github.com/benchristel)! - Remove unused "Show ruler" option from the interactive graph editor. The new Mafs version of the interactive graph does not implement the ruler, and we have no plans to implement it, since it can't be made accessible and isn't used in Khan Academy's existing content. - [#1450](#1450) [`2216ad012`](2216ad0) Thanks [@handeyeco](https://github.com/handeyeco)! - Remove Unit aka UnitInput widget ### Minor Changes - [#1422](#1422) [`c386515ad`](c386515) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph Editor] Segment and Linear System graph start coords UI ### Patch Changes - [#1446](#1446) [`4985d2d4c`](4985d2d) Thanks [@nishasy](https://github.com/nishasy)! - Rename StartCoordSettings to StartCoordsSettings - [#1448](#1448) [`84675574c`](8467557) Thanks [@nishasy](https://github.com/nishasy)! - [Interactive Graph Editor] Refactor and clean up start coords UI implementation - Updated dependencies \[[`b868801fa`](b868801), [`84675574c`](8467557), [`7e71f8e8a`](7e71f8e), [`9bc4812fc`](9bc4812), [`130ab9446`](130ab94), [`9bc264ce1`](9bc264c), [`bb1ac584b`](bb1ac58), [`2216ad012`](2216ad0), [`7a448e77c`](7a448e7), [`c386515ad`](c386515)]: - @khanacademy/[email protected] - @khanacademy/[email protected] ## @khanacademy/[email protected] ### Patch Changes - [#1454](#1454) [`7e71f8e8a`](7e71f8e) Thanks [@Myranae](https://github.com/Myranae)! - Update mathjax-renderer version ## @khanacademy/[email protected] ### Patch Changes - Updated dependencies \[[`7e71f8e8a`](7e71f8e)]: - @khanacademy/[email protected] Author: khan-actions-bot Reviewers: benchristel Required Reviewers: Approved By: benchristel Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ⏭️ Publish npm snapshot, ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1443
Summary:
Throttles the events in polygon to increase performance and decrease CPU load. This is especially important for Safari. This change lowers CPU usage from 87% to 30% on a M3 macbook. The increase in performance will be more on phones and iPads where this will also decrease energy usage.
40 FPS was chosen as a mark that feels response and good to use but doesn't put too much stress on the machine.
Issue: https://khanacademy.atlassian.net/browse/LEMS-2185
Test plan:
To test before:
To test after: