Skip to content

Refactor ReactProfilerTimer to Track Transition Timers Per Lane#35759

Open
subhamkumarr wants to merge 3 commits intofacebook:mainfrom
subhamkumarr:fix-profiler-transition-timers
Open

Refactor ReactProfilerTimer to Track Transition Timers Per Lane#35759
subhamkumarr wants to merge 3 commits intofacebook:mainfrom
subhamkumarr:fix-profiler-transition-timers

Conversation

@subhamkumarr
Copy link

Summary

This PR refactors ReactProfilerTimer.js to correctly track transition timers on a per-lane basis, addressing a long-standing TODO (// TODO: This should really be one per Transition lane.).

Previously, transition timings (start time, update time, event time) were stored in global variables (transitionStartTime, transitionUpdateTime, etc.). This caused issues when multiple transitions were being processed concurrently or interleaved, as the global state could be overwritten, leading to inaccurate profiling data.

Key Changes

packages/react-reconciler/src/ReactProfilerTimer.js

  • Replaced global transition timer variables with a transitionTimers Map, keyed by Lane.
  • Introduced WeakMaps (pendingTransitionStartTimes, pendingTransitionEventInfo) to buffer timing data associated with a Transition object before a specific Lane is assigned.
  • Updated startUpdateTimerByLane, startHostActionTimer, startAsyncTransitionTimer, and other helper functions to read/write from the transitionTimers Map instead of global variables.
  • Added getTransitionTimers(lane) to safely retrieve timer data for a specific lane.

packages/react-reconciler/src/ReactFiberWorkLoop.js

  • Updated the includesTransitionLane block in the work loop logic.
  • It now iterates through all active transition lanes using getHighestPriorityLane.
  • For each lane, it retrieves the corresponding timer data and logs the transition start/update.
  • Ensures clearTransitionTimer(lane) is called for the specific lane being processed, rather than a global clear.

Verification

Automated Tests

  • Passed yarn test packages/react-reconciler/src/__tests__/ReactTransitionTracing-test.js
  • Passed yarn test packages/react-reconciler/src/__tests__/ReactPerformanceTrack-test.js

Manual Verification

  • Verified that no regressions were introduced in basic profiling behavior.

Related Issues

Fixes TODO in ReactProfilerTimer.js.

@meta-cla meta-cla bot added the CLA Signed label Feb 10, 2026
@subhamkumarr subhamkumarr force-pushed the fix-profiler-transition-timers branch from 9a94135 to 06bebe9 Compare February 10, 2026 16:34
@subhamkumarr subhamkumarr force-pushed the fix-profiler-transition-timers branch from 06bebe9 to 8ed1e6e Compare February 10, 2026 16:47
@eps1lon
Copy link
Collaborator

eps1lon commented Feb 10, 2026

Can you think of some tests to add (e.g. in ReactTransitionTracing-test.js) that show the difference with the new implementation?

@subhamkumarr
Copy link
Author

Can you think of some tests to add (e.g. in ReactTransitionTracing-test.js) that show the difference with the new implementation?

Done! I added a regression test in ReactTransitionTracing-test.js called should correctly track start times for interleaved transitions.

It starts two transitions (at 1000ms and 2000ms) on separate roots and verifies they complete with their distinct start times, confirming they don't overwrite each other's global state.

@aydenhailey78-hub
Copy link

aydenhailey78-hub commented Feb 10, 2026 via email

@djhdusjbd-eng
Copy link

djhdusjbd-eng commented Feb 10, 2026 via email

@subhamkumarr
Copy link
Author

@eps1lon
Is this Ok?

@subhamkumarr
Copy link
Author

@hoxyq @eps1lon @unstubbable @jackpope
could anyone please review this and merge it when you get a chance? Thanks!
Fixes #35757

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants