perf: FIT-1295: Add React memoization to hot rendering paths#9261
Closed
perf: FIT-1295: Add React memoization to hot rendering paths#9261
Conversation
Add useCallback, useMemo, and React.memo to components that are rendered frequently to prevent unnecessary re-renders. Changes: - VideoRegions.jsx: Extract Shape onClick handler with useCallback, memoize selected regions filter - RegionLabels.tsx: Add memoized LabelItem component, memoize label extraction - Choices.jsx: Extract Select onChange handler with useCallback - PolygonRegion.jsx: Extract Edge handlers with useCallback, memoize flattenedPoints and lineProps These optimizations reduce function recreation on each render and help React's reconciliation process skip unnecessary updates.
✅ Deploy Preview for heartex-docs canceled.
|
✅ Deploy Preview for label-studio-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for label-studio-playground ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
|
||
| // Memoized label item component to prevent unnecessary re-renders | ||
| const LabelItem = memo(({ label, showComma }: { label: any; showComma: boolean }) => { | ||
| const color = label.background || "#000000"; |
Contributor
There was a problem hiding this comment.
rather than #000000 lets have a safe default from our css tokens
✅ Deploy Preview for label-studio-docs-new-theme canceled.
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
yyassi-heartex
approved these changes
Jan 26, 2026
Collaborator
|
This PR is stale because it has been open 45 days with no activity. Remove |
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.
Problem
Inline function handlers are recreated on every render, causing child components to receive new prop references and re-render unnecessarily. This is particularly impactful in hot paths like VideoRegions, Choices, and PolygonRegion.
Solution
Add
useCallbackfor event handlers anduseMemofor computed values to prevent unnecessary re-renders.Files Changed
web/libs/editor/src/tags/object/Video/VideoRegions.jsxweb/libs/editor/src/tags/control/Choices.jsxweb/libs/editor/src/regions/PolygonRegion.jsxweb/libs/editor/src/components/SidePanels/DetailsPanel/RegionLabels.tsx