Skip to content

perf: FIT-1295: Add React memoization to hot rendering paths#9261

Closed
bmartel wants to merge 1 commit intodevelopfrom
fb-fit-1295
Closed

perf: FIT-1295: Add React memoization to hot rendering paths#9261
bmartel wants to merge 1 commit intodevelopfrom
fb-fit-1295

Conversation

@bmartel
Copy link
Copy Markdown
Contributor

@bmartel bmartel commented Jan 26, 2026

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 useCallback for event handlers and useMemo for computed values to prevent unnecessary re-renders.

Files Changed

  • web/libs/editor/src/tags/object/Video/VideoRegions.jsx
  • web/libs/editor/src/tags/control/Choices.jsx
  • web/libs/editor/src/regions/PolygonRegion.jsx
  • web/libs/editor/src/components/SidePanels/DetailsPanel/RegionLabels.tsx

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.
@bmartel bmartel requested a review from a team January 26, 2026 18:18
@github-actions github-actions bot added the perf label Jan 26, 2026
@netlify
Copy link
Copy Markdown

netlify bot commented Jan 26, 2026

Deploy Preview for heartex-docs canceled.

Name Link
🔨 Latest commit b6d2e78
🔍 Latest deploy log https://app.netlify.com/projects/heartex-docs/deploys/6977aff5f51b4900085de9a8

@netlify
Copy link
Copy Markdown

netlify bot commented Jan 26, 2026

Deploy Preview for label-studio-storybook ready!

Name Link
🔨 Latest commit b6d2e78
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-storybook/deploys/6977aff55fbb980008427535
😎 Deploy Preview https://deploy-preview-9261--label-studio-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify bot commented Jan 26, 2026

Deploy Preview for label-studio-playground ready!

Name Link
🔨 Latest commit b6d2e78
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-playground/deploys/6977aff5d13d840008522a40
😎 Deploy Preview https://deploy-preview-9261--label-studio-playground.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rather than #000000 lets have a safe default from our css tokens

@netlify
Copy link
Copy Markdown

netlify bot commented Jan 26, 2026

Deploy Preview for label-studio-docs-new-theme canceled.

Name Link
🔨 Latest commit b6d2e78
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-docs-new-theme/deploys/6977aff5ed45cd0008e33bad

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 69.76744% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
web/libs/editor/src/tags/control/Choices.jsx 20.00% 8 Missing ⚠️
web/libs/editor/src/regions/PolygonRegion.jsx 69.23% 4 Missing ⚠️
...libs/editor/src/tags/object/Video/VideoRegions.jsx 90.90% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@robot-ci-heartex
Copy link
Copy Markdown
Collaborator

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants