Skip to content
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

Track which fibers scheduled the current render work #15658

Merged
merged 2 commits into from
Apr 9, 2021

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented May 15, 2019

This PR introduces the concept of tracking which Fiber(s) schedule work with React.

Tracked Fibers are called "updaters" and are exposed to DevTools via a memoizedUpdaters property on the ReactFiberRoot. The implementation of this feature follows a vaguely similar approach as interaction tracing, but does not require reference counting since there is no subscriptions API.

This change is in support of a new DevTools Profiler feature that shows which Fiber(s) scheduled the selected commit in the Profiler.

All changes have been gated behind a new feature flag, enableUpdaterTracking, which is enabled for Profiling builds by default. We also only track updaters when DevTools has been detected, to avoid doing unnecessary work.

@sizebot
Copy link

sizebot commented May 15, 2019

ReactDOM: size: 0.0%, gzip: 🔺+0.1%

Details of bundled changes.

Comparing: 50b50c2...91b3678

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.5% +0.3% 848.29 KB 852.15 KB 193.3 KB 193.92 KB UMD_DEV
react-dom.production.min.js 0.0% 🔺+0.1% 105.07 KB 105.11 KB 34.14 KB 34.18 KB UMD_PROD
react-dom.profiling.min.js +0.6% +0.6% 108.25 KB 108.94 KB 35.18 KB 35.4 KB UMD_PROFILING
react-dom.development.js +0.5% +0.3% 842.61 KB 846.47 KB 191.74 KB 192.36 KB NODE_DEV
react-dom.production.min.js 0.0% 🔺+0.1% 105.07 KB 105.09 KB 33.58 KB 33.6 KB NODE_PROD
react-dom.profiling.min.js +0.6% +0.6% 108.43 KB 109.1 KB 34.45 KB 34.65 KB NODE_PROFILING
ReactDOM-dev.js +0.5% +0.3% 868.13 KB 872.09 KB 193.34 KB 194 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.2% 🔺+0.1% 353.02 KB 353.79 KB 65.32 KB 65.4 KB FB_WWW_PROD
ReactDOM-profiling.js +1.1% +1.0% 358.16 KB 362.28 KB 66.29 KB 66.93 KB FB_WWW_PROFILING
react-dom-unstable-fire.development.js +0.5% +0.3% 848.64 KB 852.5 KB 193.44 KB 194.06 KB UMD_DEV
react-dom-unstable-fire.production.min.js 0.0% 🔺+0.1% 105.09 KB 105.13 KB 34.15 KB 34.19 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js +0.6% +0.6% 108.26 KB 108.95 KB 35.18 KB 35.41 KB UMD_PROFILING
react-dom-unstable-fire.development.js +0.5% +0.3% 842.96 KB 846.81 KB 191.88 KB 192.5 KB NODE_DEV
react-dom-unstable-fire.production.min.js 0.0% 🔺+0.1% 105.08 KB 105.1 KB 33.59 KB 33.61 KB NODE_PROD
react-dom-unstable-fire.profiling.min.js +0.6% +0.6% 108.44 KB 109.11 KB 34.46 KB 34.66 KB NODE_PROFILING
ReactFire-dev.js +0.5% +0.3% 867.34 KB 871.29 KB 193.28 KB 193.95 KB FB_WWW_DEV
ReactFire-prod.js 🔺+0.2% 🔺+0.1% 340.96 KB 341.73 KB 62.93 KB 62.99 KB FB_WWW_PROD
ReactFire-profiling.js +0.8% +0.7% 346.11 KB 348.99 KB 63.88 KB 64.29 KB FB_WWW_PROFILING
react-dom-test-utils.development.js +0.1% +0.1% 56.93 KB 56.98 KB 15.68 KB 15.7 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.76 KB 10.76 KB 3.94 KB 3.95 KB UMD_PROD
react-dom-test-utils.development.js +0.1% +0.1% 55.27 KB 55.32 KB 15.36 KB 15.38 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.51 KB 10.51 KB 3.88 KB 3.88 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.76 KB 60.76 KB 15.85 KB 15.85 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.69 KB 10.69 KB 3.67 KB 3.67 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.43 KB 60.43 KB 15.72 KB 15.72 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.43 KB 10.43 KB 3.56 KB 3.57 KB NODE_PROD
react-dom-server.browser.development.js 0.0% +0.1% 137.21 KB 137.26 KB 36.17 KB 36.19 KB UMD_DEV
react-dom-server.browser.development.js 0.0% +0.1% 133.34 KB 133.39 KB 35.23 KB 35.25 KB NODE_DEV
ReactDOMServer-dev.js 0.0% 0.0% 135.54 KB 135.54 KB 34.8 KB 34.81 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% 0.0% 47.98 KB 47.98 KB 11.04 KB 11.04 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% +0.1% 135.28 KB 135.33 KB 35.78 KB 35.8 KB NODE_DEV
react-dom-server.node.production.min.js 0.0% -0.0% 19.98 KB 19.98 KB 7.53 KB 7.53 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.81 KB 3.81 KB 1.54 KB 1.54 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.21 KB 1.21 KB 705 B 707 B UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.64 KB 3.64 KB 1.49 KB 1.49 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.05 KB 1.05 KB 636 B 638 B NODE_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.88 KB 3.88 KB 1.51 KB 1.51 KB NODE_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.1% 1.1 KB 1.1 KB 667 B 668 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.7% +0.5% 584.2 KB 588.05 KB 127.86 KB 128.46 KB UMD_DEV
react-art.production.min.js 0.0% 🔺+0.1% 96.76 KB 96.78 KB 29.8 KB 29.83 KB UMD_PROD
react-art.development.js +0.7% +0.5% 515.1 KB 518.96 KB 110.37 KB 110.97 KB NODE_DEV
react-art.production.min.js 0.0% 🔺+0.2% 61.74 KB 61.75 KB 19.06 KB 19.09 KB NODE_PROD
ReactART-dev.js +0.8% +0.6% 525.5 KB 529.46 KB 109.71 KB 110.33 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.3% 🔺+0.2% 201.21 KB 201.76 KB 34.29 KB 34.37 KB FB_WWW_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.6% +0.4% 657.77 KB 661.73 KB 140.05 KB 140.68 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.2% 🔺+0.2% 249.18 KB 249.75 KB 43.36 KB 43.44 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +1.0% +1.0% 257.11 KB 259.76 KB 44.97 KB 45.41 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.6% +0.4% 657.68 KB 661.64 KB 140.02 KB 140.65 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.2% 🔺+0.2% 249.19 KB 249.76 KB 43.36 KB 43.43 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +1.0% +1.0% 257.12 KB 259.78 KB 44.97 KB 45.41 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.6% +0.5% 646.52 KB 650.48 KB 137.33 KB 137.96 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.3% 🔺+0.3% 242.37 KB 243.05 KB 42.02 KB 42.15 KB RN_FB_PROD
ReactFabric-profiling.js +1.1% +0.9% 250.31 KB 253.07 KB 43.69 KB 44.1 KB RN_FB_PROFILING
ReactFabric-dev.js +0.6% +0.5% 646.43 KB 650.39 KB 137.3 KB 137.92 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.3% 🔺+0.3% 242.38 KB 243.05 KB 42.02 KB 42.15 KB RN_OSS_PROD
ReactFabric-profiling.js +1.1% +0.9% 250.33 KB 253.08 KB 43.69 KB 44.1 KB RN_OSS_PROFILING

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.7% +0.5% 528.48 KB 532.29 KB 113.22 KB 113.82 KB UMD_DEV
react-test-renderer.production.min.js 0.0% 🔺+0.1% 63.03 KB 63.05 KB 19.46 KB 19.48 KB UMD_PROD
react-test-renderer.development.js +0.7% +0.5% 524.02 KB 527.83 KB 112.11 KB 112.71 KB NODE_DEV
react-test-renderer.production.min.js 0.0% 🔺+0.2% 62.71 KB 62.73 KB 19.25 KB 19.29 KB NODE_PROD
ReactTestRenderer-dev.js +0.7% +0.6% 536.48 KB 540.44 KB 112.19 KB 112.82 KB FB_WWW_DEV
react-test-renderer-shallow.development.js +0.1% +0.2% 41.95 KB 41.99 KB 10.83 KB 10.85 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% 0.0% 11.6 KB 11.6 KB 3.55 KB 3.55 KB UMD_PROD
react-test-renderer-shallow.development.js +0.1% +0.2% 36.08 KB 36.13 KB 9.46 KB 9.48 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% 0.0% 11.74 KB 11.74 KB 3.67 KB 3.67 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.8% +0.6% 512.21 KB 516.07 KB 108.79 KB 109.41 KB NODE_DEV
react-reconciler.production.min.js 0.0% 🔺+0.2% 62.74 KB 62.76 KB 18.85 KB 18.89 KB NODE_PROD
react-reconciler-persistent.development.js +0.7% +0.6% 509.89 KB 513.7 KB 107.78 KB 108.39 KB NODE_DEV
react-reconciler-persistent.production.min.js 0.0% 🔺+0.2% 62.75 KB 62.77 KB 18.86 KB 18.89 KB NODE_PROD
react-reconciler-reflection.development.js +0.2% +0.3% 19.16 KB 19.21 KB 6.08 KB 6.1 KB NODE_DEV
react-reconciler-reflection.production.min.js 0.0% 🔺+0.1% 2.51 KB 2.51 KB 1.11 KB 1.12 KB NODE_PROD

Generated by 🚫 dangerJS

@bvaughn bvaughn changed the title [WIP] Profiler proof of concept (do not merge) Track which fibers scheduled the current render work May 16, 2019
@bvaughn bvaughn force-pushed the scheduler-tracking branch 2 times, most recently from efc6f2e to f0562c7 Compare May 16, 2019 20:48
@bvaughn
Copy link
Contributor Author

bvaughn commented May 18, 2019

I think there's a cycle here in some cases where flushing pending updates can cause the updater to get lost. I can reliably reproduce it in a small test app (below). If I type a couple of characters, I'll get a commit with no updaters.

function Input() {
  const [text, setText] = useState('');
  const handleChange = event => setText(event.currentTarget.value);
  // To reproduce the bug, type (more than once) into the input below.
  return <input type="text" value={text} onChange={handleChange} />;
}

// The bug doesn't occur in a sync root:
// render(<Input />, document.getElementById('root'));

const root = createRoot(document.getElementById('root'));
root.render(<Input />);

Haven't been able to catch it in a test yet, because the flushing behavior is different.

I think I have a fix for this but I would feel better about it if I could capture the broken behavior in a test first.

@bvaughn
Copy link
Contributor Author

bvaughn commented May 18, 2019

Okay. I think I captured a variant of the bug in a new test (failing before) and fixed.

@bvaughn
Copy link
Contributor Author

bvaughn commented May 20, 2019

Rebased after #15664 landed.

@acdlite
Copy link
Collaborator

acdlite commented May 20, 2019

I'm going to defer to @sebmarkbage to review this since I think you discussed the overall approach with him already

@bvaughn
Copy link
Contributor Author

bvaughn commented May 20, 2019

Lucky @sebmarkbage 🎉

@bvaughn
Copy link
Contributor Author

bvaughn commented May 29, 2019

Ping @sebmarkbage 😄

@necolas necolas added the React Core Team Opened by a member of the React Core Team label Jan 8, 2020
@bvaughn
Copy link
Contributor Author

bvaughn commented Jan 23, 2020

I think this PR is still worth at least considering. Leaving open for now until @sebmarkbage indicates level of interest. (If interested, I'll rebase.)

@bvaughn
Copy link
Contributor Author

bvaughn commented Mar 29, 2021

This would have been a useful feature 😄 It's unfortunate that it never got reviewed.

@gaearon
Copy link
Collaborator

gaearon commented Mar 29, 2021

I can review it! I don't think I've seen it before. I doubt Seb sees GH mentions. :)

@bvaughn
Copy link
Contributor Author

bvaughn commented Mar 30, 2021

I don't think I've seen it before.

Screen Shot 2021-03-29 at 10 24 26 PM

🤣 At least I'm not the only one who does this!

Thanks for the offer Dan! I'll clean it up sometime this week and ping you.

@gaearon
Copy link
Collaborator

gaearon commented Mar 30, 2021

It’s been... a while.

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 1, 2021

Well fortunately, only....everything...has changed since I wrote this. Should not be a problem.

@bvaughn bvaughn marked this pull request as draft April 1, 2021 02:56
@bvaughn bvaughn changed the title Track which fibers scheduled the current render work [draft] Track which fibers scheduled the current render work Apr 1, 2021
@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 1, 2021

I'm returning this to draft status while I work on rebasing and updating the expiration times logic to lanes logic.

Comment on lines 750 to 800
export function addFiberToLanesMap(
root: FiberRoot,
fiber: Fiber,
lanes: Lanes | Lane,
) {
if (enableUpdaterTracking) {
if (isDevToolsPresent) {
const pendingUpdatersLaneMap = root.pendingUpdatersLaneMap;
while (lanes > 0) {
const index = laneToIndex(lanes);
const lane = 1 << index;

const updaters = pendingUpdatersLaneMap[index];
updaters.add(fiber);

lanes &= ~lane;
}
}
}
}

export function movePendingFibersToMemoized(root: FiberRoot, lanes: Lanes) {
if (enableUpdaterTracking) {
if (isDevToolsPresent) {
const pendingUpdatersLaneMap = root.pendingUpdatersLaneMap;
const memoizedUpdaters = root.memoizedUpdaters;
while (lanes > 0) {
const index = laneToIndex(lanes);
const lane = 1 << index;

const updaters = pendingUpdatersLaneMap[index];
if (updaters.size > 0) {
updaters.forEach(fiber => {
const alternate = fiber.alternate;
if (alternate === null || !memoizedUpdaters.has(alternate)) {
memoizedUpdaters.add(fiber);
}
});
updaters.clear();
}

lanes &= ~lane;
}
}
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seemed best to put these functions in ReactFiberLane so they had access to laneToIndex to make lanes->indices mapping easier.

@sizebot
Copy link

sizebot commented Apr 2, 2021

Comparing: 6ea7491...ff40a42

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 122.58 kB 122.58 kB +0.07% 39.32 kB 39.35 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 129.14 kB 129.14 kB +0.05% 41.41 kB 41.43 kB
facebook-www/ReactDOM-prod.classic.js = 411.73 kB 411.73 kB +0.02% 76.17 kB 76.19 kB
facebook-www/ReactDOM-prod.modern.js = 399.79 kB 399.79 kB = 74.29 kB 74.28 kB
facebook-www/ReactDOMForked-prod.classic.js = 411.73 kB 411.73 kB +0.02% 76.18 kB 76.19 kB
oss-experimental/react-reconciler/cjs/react-reconciler-constants.development.js +61.12% 1.06 kB 1.70 kB +66.82% 0.45 kB 0.74 kB
oss-stable/react-reconciler/cjs/react-reconciler-constants.development.js +61.12% 1.06 kB 1.70 kB +66.82% 0.45 kB 0.74 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-reconciler/cjs/react-reconciler-constants.development.js +61.12% 1.06 kB 1.70 kB +66.82% 0.45 kB 0.74 kB
oss-stable/react-reconciler/cjs/react-reconciler-constants.development.js +61.12% 1.06 kB 1.70 kB +66.82% 0.45 kB 0.74 kB
oss-stable/react-reconciler/cjs/react-reconciler.profiling.min.js +0.97% 90.78 kB 91.66 kB +1.08% 28.09 kB 28.39 kB
oss-experimental/react-reconciler/cjs/react-reconciler.profiling.min.js +0.89% 98.21 kB 99.09 kB +1.11% 30.37 kB 30.71 kB
facebook-www/ReactDOM-profiling.modern.js +0.76% 421.95 kB 425.17 kB +0.82% 78.08 kB 78.72 kB
facebook-www/ReactDOMForked-profiling.modern.js +0.76% 421.95 kB 425.17 kB +0.82% 78.09 kB 78.73 kB
facebook-www/ReactDOM-profiling.classic.js +0.74% 433.93 kB 437.15 kB +0.84% 79.92 kB 80.59 kB
facebook-www/ReactDOMForked-profiling.classic.js +0.74% 433.93 kB 437.15 kB +0.84% 79.92 kB 80.59 kB
oss-stable/react-art/cjs/react-art.development.js +0.72% 593.17 kB 597.46 kB +0.63% 130.09 kB 130.91 kB
facebook-www/ReactIs-dev.classic.js +0.72% 9.92 kB 9.99 kB +0.48% 2.70 kB 2.71 kB
facebook-www/ReactIs-dev.modern.js +0.70% 10.19 kB 10.26 kB +0.47% 2.74 kB 2.76 kB
oss-stable/react-dom/cjs/react-dom.profiling.min.js +0.70% 126.82 kB 127.70 kB +0.79% 40.63 kB 40.95 kB
oss-experimental/react-art/cjs/react-art.development.js +0.68% 634.97 kB 639.26 kB +0.61% 138.49 kB 139.33 kB
facebook-www/ReactART-dev.modern.js +0.67% 701.71 kB 706.44 kB +0.62% 149.50 kB 150.43 kB
facebook-www/ReactART-dev.classic.js +0.66% 712.00 kB 716.73 kB +0.61% 151.55 kB 152.48 kB
oss-stable/react-reconciler/cjs/react-reconciler.development.js +0.66% 649.39 kB 653.68 kB +0.61% 139.33 kB 140.18 kB
oss-stable/react-dom/umd/react-dom.profiling.min.js +0.66% 126.73 kB 127.56 kB +0.79% 41.27 kB 41.60 kB
oss-stable/react-art/umd/react-art.development.js +0.65% 693.90 kB 698.43 kB +0.56% 148.17 kB 149.00 kB
oss-experimental/react-dom/cjs/react-dom.profiling.min.js +0.65% 135.43 kB 136.31 kB +0.72% 43.31 kB 43.63 kB
facebook-www/SchedulerTracing-dev.modern.js +0.63% 11.21 kB 11.28 kB +0.53% 2.48 kB 2.49 kB
facebook-www/SchedulerTracing-dev.classic.js +0.63% 11.21 kB 11.29 kB +0.53% 2.48 kB 2.49 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js +0.62% 693.85 kB 698.14 kB +0.58% 148.33 kB 149.19 kB
oss-experimental/react-art/umd/react-art.development.js +0.61% 737.84 kB 742.37 kB +0.56% 156.84 kB 157.72 kB
oss-experimental/react-dom/umd/react-dom.profiling.min.js +0.61% 135.28 kB 136.11 kB +0.65% 44.01 kB 44.30 kB
oss-stable/react-dom/umd/react-dom.development.js +0.48% 952.28 kB 956.82 kB +0.37% 209.18 kB 209.95 kB
oss-stable/react-dom/cjs/react-dom.development.js +0.47% 905.92 kB 910.21 kB +0.39% 206.54 kB 207.35 kB
facebook-www/ReactDOMForked-dev.modern.js +0.45% 1,039.94 kB 1,044.67 kB +0.44% 230.88 kB 231.91 kB
facebook-www/ReactDOM-dev.modern.js +0.45% 1,039.94 kB 1,044.67 kB +0.44% 230.88 kB 231.91 kB
oss-experimental/react-dom/umd/react-dom.development.js +0.45% 1,006.58 kB 1,011.11 kB +0.34% 219.49 kB 220.23 kB
oss-experimental/react-dom/cjs/react-dom.development.js +0.45% 957.58 kB 961.87 kB +0.38% 216.70 kB 217.53 kB
facebook-www/ReactDOMForked-dev.classic.js +0.44% 1,066.18 kB 1,070.91 kB +0.43% 236.32 kB 237.34 kB
facebook-www/ReactDOM-dev.classic.js +0.44% 1,066.18 kB 1,070.91 kB +0.43% 236.32 kB 237.34 kB

Generated by 🚫 dangerJS against ff40a42

@sebmarkbage
Copy link
Collaborator

Didn't see pings on GH.

I think I must have forgotten a lot of the context here.

But as I read it, this is really mostly because we want to track it through retries of Suspense and Offscreen. Is that right?

Because otherwise we can infer this info in the devtools when we loop over the tree after a commit. If it's just for that commit.

This is similar to how the Cache has to attach itself to a Suspense boundary.

I wonder if this would be more scoped if we did it that way. We could store the parents that participated in an update on an internal context and then snapshot that on the Suspense/Offscreen/Hydrating boundary.

Then devtools would pick up this info in the traversal of the commit either from the updated hook or the suspense boundary that was retries.

There's a subtle difference also if you create this list when something is called with setState on it vs if it participated in the render. Because things that called setState but that thing was deleted or in a hidden subtree didn't contribute to the rendering (just the cloning) of that commit. Not sure which one is better.

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 2, 2021

But as I read it, this is really mostly because we want to track it through retries of Suspense and Offscreen. Is that right?

Yes.

I wonder if this would be more scoped if we did it that way. We could store the parents that participated in an update on an internal context and then snapshot that on the Suspense/Offscreen/Hydrating boundary.

Then devtools would pick up this info in the traversal of the commit either from the updated hook or the suspense boundary that was retries.

Some initial concern at the idea of maintaining that over time, across React versions. Seems like the internal logic of Suspense (and Offscreen) has already changed a lot and will likely be changing more (e.g. with effects semantics) – something explicit feels more future proof.

@bvaughn bvaughn changed the title [draft] Track which fibers scheduled the current render work Track which fibers scheduled the current render work Apr 2, 2021
@bvaughn bvaughn marked this pull request as ready for review April 2, 2021 21:56
@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 3, 2021

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 9, 2021

Can I get a review of this please? :)

This change is gated behind a new profiling-mode-only feature flag, "enableUpdaterTracking".
Copy link
Collaborator

@sebmarkbage sebmarkbage left a comment

Choose a reason for hiding this comment

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

We can discuss alternative approaches that may or may not be more accurate for a longer term solution but don't want to block the UI features.

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 9, 2021

Much appreciated!

@bvaughn bvaughn merged commit dc108b0 into facebook:master Apr 9, 2021
@bvaughn bvaughn deleted the scheduler-tracking branch April 9, 2021 14:34
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Apr 20, 2021
Summary:
This sync includes the following changes:
- **[f7cdc8936](facebook/react@f7cdc8936 )**: Also turn off enableSyncDefaultUpdates in RN test renderer ([#21293](facebook/react#21293)) //<Ricky>//
- **[4c9eb2af1](facebook/react@4c9eb2af1 )**: Add dynamic flags to React Native ([#21291](facebook/react#21291)) //<Ricky>//
- **[9eddfbf5a](facebook/react@9eddfbf5a )**: [Fizz] Two More Fixes ([#21288](facebook/react#21288)) //<Sebastian Markbåge>//
- **[11b07597e](facebook/react@11b07597e )**: Fix classes ([#21283](facebook/react#21283)) //<Sebastian Markbåge>//
- **[96d00b9bb](facebook/react@96d00b9bb )**: [Fizz] Random Fixes ([#21277](facebook/react#21277)) //<Sebastian Markbåge>//
- **[81ef53953](facebook/react@81ef53953 )**: Always insert a dummy node with an ID into fallbacks ([#21272](facebook/react#21272)) //<Sebastian Markbåge>//
- **[a4a940d7a](facebook/react@a4a940d7a )**: [Fizz] Add unsupported Portal/Scope components ([#21261](facebook/react#21261)) //<Sebastian Markbåge>//
- **[f4d7a0f1e](facebook/react@f4d7a0f1e )**: Implement useOpaqueIdentifier ([#21260](facebook/react#21260)) //<Sebastian Markbåge>//
- **[dde875dfb](facebook/react@dde875dfb )**: [Fizz] Implement Hooks ([#21257](facebook/react#21257)) //<Sebastian Markbåge>//
- **[a597c2f5d](facebook/react@a597c2f5d )**: [Fizz] Fix reentrancy bug ([#21270](facebook/react#21270)) //<Sebastian Markbåge>//
- **[15e779d92](facebook/react@15e779d92 )**: Reconciler should inject its own version into DevTools hook ([#21268](facebook/react#21268)) //<Brian Vaughn>//
- **[4f76a28c9](facebook/react@4f76a28c9 )**: [Fizz] Implement New Context ([#21255](facebook/react#21255)) //<Sebastian Markbåge>//
- **[82ef450e0](facebook/react@82ef450e0 )**: remove obsolete SharedArrayBuffer ESLint config ([#21259](facebook/react#21259)) //<Henry Q. Dineen>//
- **[dbadfa2c3](facebook/react@dbadfa2c3 )**: [Fizz] Classes Follow Up ([#21253](facebook/react#21253)) //<Sebastian Markbåge>//
- **[686b635b7](facebook/react@686b635b7 )**: Prevent reading canonical property of null ([#21242](facebook/react#21242)) //<Joshua Gross>//
- **[bb88ce95a](facebook/react@bb88ce95a )**: Bugfix: Don't rely on `finishedLanes` for passive effects ([#21233](facebook/react#21233)) //<Andrew Clark>//
- **[343710c92](facebook/react@343710c92 )**: [Fizz] Fragments and Iterable support ([#21228](facebook/react#21228)) //<Sebastian Markbåge>//
- **[933880b45](facebook/react@933880b45 )**: Make time-slicing opt-in ([#21072](facebook/react#21072)) //<Ricky>//
- **[b0407b55f](facebook/react@b0407b55f )**: Support more empty types ([#21225](facebook/react#21225)) //<Sebastian Markbåge>//
- **[39713716a](facebook/react@39713716a )**: Merge isObject branches ([#21226](facebook/react#21226)) //<Sebastian Markbåge>//
- **[8a4a59c72](facebook/react@8a4a59c72 )**: Remove textarea special case from child fiber ([#21222](facebook/react#21222)) //<Sebastian Markbåge>//
- **[dc108b0f5](facebook/react@dc108b0f5 )**: Track which fibers scheduled the current render work ([#15658](facebook/react#15658)) //<Brian Vaughn>//
- **[6ea749170](facebook/react@6ea749170 )**: Fix typo in comment ([#21214](facebook/react#21214)) //<inokawa>//
- **[b38ac13f9](facebook/react@b38ac13f9 )**: DevTools: Add post-commit hook ([#21183](facebook/react#21183)) //<Brian Vaughn>//
- **[b943aeba8](facebook/react@b943aeba8 )**: Fix: Passive effect updates are never sync ([#21215](facebook/react#21215)) //<Andrew Clark>//
- **[d389c54d1](facebook/react@d389c54d1 )**: Offscreen: Use JS stack to track hidden/unhidden subtree state ([#21211](facebook/react#21211)) //<Brian Vaughn>//
- **[c486dc1a4](facebook/react@c486dc1a4 )**: Remove unnecessary processUpdateQueue ([#21199](facebook/react#21199)) //<Sebastian Markbåge>//
- **[cf45a623a](facebook/react@cf45a623a )**: [Fizz] Implement Classes ([#21200](facebook/react#21200)) //<Sebastian Markbåge>//
- **[75c616554](facebook/react@75c616554 )**: Include actual type of `Profiler#id` on type mismatch ([#20306](facebook/react#20306)) //<Sebastian Silbermann>//
- **[1214b302e](facebook/react@1214b302e )**: test: Fix "couldn't locate all inline snapshots" ([#21205](facebook/react#21205)) //<Sebastian Silbermann>//
- **[1a02d2792](facebook/react@1a02d2792 )**: style: delete unused isHost check ([#21203](facebook/react#21203)) //<wangao>//
- **[782f689ca](facebook/react@782f689ca )**: Don't double invoke getDerivedStateFromProps for module pattern ([#21193](facebook/react#21193)) //<Sebastian Markbåge>//
- **[e90c76a65](facebook/react@e90c76a65 )**: Revert "Offscreen: Use JS stack to track hidden/unhidden subtree state" ([#21194](facebook/react#21194)) //<Brian Vaughn>//
- **[1f8583de8](facebook/react@1f8583de8 )**: Offscreen: Use JS stack to track hidden/unhidden subtree state ([#21192](facebook/react#21192)) //<Brian Vaughn>//
- **[ad6e6ec7b](facebook/react@ad6e6ec7b )**: [Fizz] Prepare Recursive Loop for More Types ([#21186](facebook/react#21186)) //<Sebastian Markbåge>//
- **[172e89b4b](facebook/react@172e89b4b )**: Reland Remove redundant initial of isArray ([#21188](facebook/react#21188)) //<Sebastian Markbåge>//
- **[7c1ba2b57](facebook/react@7c1ba2b57 )**: Proposed new Suspense layout effect semantics ([#21079](facebook/react#21079)) //<Brian Vaughn>//
- **[316aa3686](facebook/react@316aa3686 )**: [Scheduler] Fix de-opt caused by out-of-bounds access ([#21147](facebook/react#21147)) //<Andrey Marchenko>//
- **[b4f119cdf](facebook/react@b4f119cdf )**: Revert "Remove redundant initial of isArray ([#21163](facebook/react#21163))" //<Sebastian Markbage>//
- **[c03197063](facebook/react@c03197063 )**: Revert "apply prettier ([#21165](facebook/react#21165))" //<Sebastian Markbage>//
- **[94fd1214d](facebook/react@94fd1214d )**: apply prettier ([#21165](facebook/react#21165)) //<Behnam Mohammadi>//
- **[b130a0f5c](facebook/react@b130a0f5c )**: Remove redundant initial of isArray ([#21163](facebook/react#21163)) //<Behnam Mohammadi>//
- **[2c9fef32d](facebook/react@2c9fef32d )**: Remove redundant initial of hasOwnProperty ([#21134](facebook/react#21134)) //<Behnam Mohammadi>//
- **[1cf9978d8](facebook/react@1cf9978d8 )**: Don't pass internals to callbacks ([#21161](facebook/react#21161)) //<Sebastian Markbåge>//
- **[b9e4c10e9](facebook/react@b9e4c10e9 )**: [Fizz] Implement all the DOM attributes and special cases ([#21153](facebook/react#21153)) //<Sebastian Markbåge>//
- **[f8ef4ff57](facebook/react@f8ef4ff57 )**: Flush discrete passive effects before paint ([#21150](facebook/react#21150)) //<Andrew Clark>//
- **[b48b38af6](facebook/react@b48b38af6 )**: Support nesting of startTransition and flushSync (alt) ([#21149](facebook/react#21149)) //<Sebastian Markbåge>//

Changelog:
[General][Changed] - React Native sync for revisions c9aab1c...f7cdc89

jest_e2e[run_all_tests]

Reviewed By: rickhanlonii

Differential Revision: D27740113

fbshipit-source-id: 6e27204d78e3e16ed205170006cb97c0d6bfa957
koto pushed a commit to koto/react that referenced this pull request Jun 15, 2021
Tracked Fibers are called "updaters" and are exposed to DevTools via a 'memoizedUpdaters' property on the ReactFiberRoot. The implementation of this feature follows a vaguely similar approach as interaction tracing, but does not require reference counting since there is no subscriptions API.

This change is in support of a new DevTools Profiler feature that shows which Fiber(s) scheduled the selected commit in the Profiler.

All changes have been gated behind a new feature flag, 'enableUpdaterTracking', which is enabled for Profiling builds by default. We also only track updaters when DevTools has been detected, to avoid doing unnecessary work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants