perf: update replay HUD labels imperatively instead of per-frame state#907
Open
Anexus5919 wants to merge 1 commit into
Open
perf: update replay HUD labels imperatively instead of per-frame state#907Anexus5919 wants to merge 1 commit into
Anexus5919 wants to merge 1 commit into
Conversation
|
@Anexus5919 is attempting to deploy a commit to the somiljain2024-4175's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
@Somil450 @diksha78dev Kindly have a review on this pr. Thanks! |
This was referenced Jun 22, 2026
The render loop called setHudLabels every frame to position the six joint-angle overlays, re-rendering the whole component at the render rate. setDisplayFPS is already throttled (every 30 frames), so setHudLabels was the per-frame re-render driver. Render the labels as a fixed set of divs once and update their position, visibility, border colour and angle text directly via refs inside the loop, so playback no longer re-renders React every frame. The projection and angle math are unchanged.
15f2914 to
b80f91c
Compare
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.
📌 Related Issue
Fixes #870
📝 Description
The
requestAnimationFramerender loop inReplay3DModel.tsxcalledsetHudLabelson every rendered frame to position the six joint-angle overlays, re-rendering the whole component at the animation frame rate. (setDisplayFPSis already throttled to every 30 frames, sosetHudLabelswas the per-frame re-render driver.)🔹 What has been changed?
src/components/Replay3DModel.tsx: the six HUD labels are now rendered once from a staticHUD_JOINTSconfig, and the loop updates each label's position, visibility, border colour and angle text directly via refs (hudRefs/hudAngleRefs) instead of viasetHudLabels. ThehudLabelsReact state (and theHudLabeltype) are removed.🔹 Why are these changes needed?
requestAnimationFrameloop should not drive React re-renders. The projection and angle math is unchanged; only the output target moves from React state to direct DOM, so playback no longer re-renders the component every frame. The CSStransitionon the labels is preserved, so label movement stays smooth.🛠️ Type of Change
🧪 Testing
✅ Tests Performed
npx tsc --noEmit:Replay3DModel.tsxis clean (the only pre-existing tsc errors are inexerciseEngine.ts, unrelated).npx eslint src/components/Replay3DModel.tsx: 0 problems — including no unused-variable warnings, confirming thehudLabelsstate andHudLabeltype were removed cleanly and the refs are wired correctly.el.style+ the angle span's text), and that the label styles match the previous markup (withdisplaytoggled to show/hide andleft/topset imperatively).🔹 Note on automated tests
No runtime unit test is included: the HUD is rendered inside a WebGL/Three.js
requestAnimationFrameloop, which is not feasible to unit test without a full WebGL + DOM harness. Verification is bytsc,eslint, and a careful review that the math/markup are unchanged.🌐 Browsers Tested
Not applicable here (verified via static analysis and review).
📷 Screenshots / Demo (if applicable)
Not applicable.
📋 Checklist
💬 Additional Notes
Branched from latest
upstream/main(5464425). Related to #869 (the same loop also re-subscribed the RAF effect every frame).