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

Add experimental DebugTracing logger for internal use #18531

Merged
merged 17 commits into from
Apr 16, 2020

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Apr 7, 2020

Ads debug logging capabilities (based on earlier experimental profiler branch) behind a new feature flag, enableDebugTracing.

@bvaughn bvaughn changed the title Debug logging Debug logging [wip] Apr 7, 2020
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Apr 7, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 7, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit b44b002:

Sandbox Source
condescending-wood-892v4 Configuration

@sizebot
Copy link

sizebot commented Apr 7, 2020

Details of bundled changes.

Comparing: b680174...b44b002

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 119.67 KB 119.73 KB 37.54 KB 37.57 KB NODE_PROD
react-dom-test-utils.development.js +0.2% +0.2% 75.12 KB 75.24 KB 20.11 KB 20.14 KB UMD_DEV
ReactDOMTesting-profiling.js +0.1% +0.1% 405.31 KB 405.52 KB 73.5 KB 73.55 KB FB_WWW_PROFILING
react-dom-server.browser.production.min.js 🔺+0.2% 🔺+0.2% 22.82 KB 22.87 KB 8.49 KB 8.51 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js +2.4% +2.0% 4.9 KB 5.01 KB 1.64 KB 1.67 KB UMD_DEV
react-dom.profiling.min.js +0.1% +0.1% 123.55 KB 123.61 KB 38.67 KB 38.7 KB NODE_PROFILING
react-dom-test-utils.production.min.js 0.0% -0.0% 13.22 KB 13.22 KB 4.9 KB 4.89 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.3% 1.19 KB 1.19 KB 699 B 697 B UMD_PROD
react-dom-server.node.development.js +0.1% +0.1% 147.14 KB 147.3 KB 38.93 KB 38.98 KB NODE_DEV
react-dom-server.node.production.min.js 🔺+0.2% 🔺+0.2% 23.23 KB 23.27 KB 8.65 KB 8.67 KB NODE_PROD
ReactDOMForked-dev.js +0.8% +0.7% 1014.87 KB 1023.07 KB 225.42 KB 226.91 KB FB_WWW_DEV
ReactDOMForked-prod.js 0.0% 🔺+0.1% 424.91 KB 425.12 KB 76.59 KB 76.64 KB FB_WWW_PROD
react-dom-unstable-fizz.node.development.js +2.2% +2.0% 5.16 KB 5.28 KB 1.69 KB 1.73 KB NODE_DEV
react-dom.development.js 0.0% 0.0% 907.88 KB 907.91 KB 199.4 KB 199.45 KB UMD_DEV
ReactDOMForked-profiling.js 0.0% +0.1% 435.87 KB 436.08 KB 78.49 KB 78.55 KB FB_WWW_PROFILING
react-dom-server.browser.development.js +0.1% +0.1% 155.09 KB 155.25 KB 39.45 KB 39.5 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% -0.3% 1.16 KB 1.16 KB 660 B 658 B NODE_PROD
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 119.55 KB 119.62 KB 38.26 KB 38.28 KB UMD_PROD
react-dom-server.browser.production.min.js 🔺+0.2% 🔺+0.2% 22.92 KB 22.97 KB 8.52 KB 8.53 KB UMD_PROD
react-dom.profiling.min.js +0.1% +0.1% 123.29 KB 123.35 KB 39.51 KB 39.53 KB UMD_PROFILING
ReactDOMTesting-dev.js 0.0% 0.0% 958.92 KB 958.94 KB 213.54 KB 213.58 KB FB_WWW_DEV
react-dom.development.js 0.0% 0.0% 864.27 KB 864.29 KB 196.95 KB 196.98 KB NODE_DEV
ReactDOMTesting-prod.js 🔺+0.1% 🔺+0.1% 405.31 KB 405.52 KB 73.5 KB 73.55 KB FB_WWW_PROD
react-dom-server.browser.development.js +0.1% +0.1% 145.92 KB 146.08 KB 38.68 KB 38.73 KB NODE_DEV
ReactDOM-dev.js +0.8% +0.7% 1014.86 KB 1023.05 KB 225.26 KB 226.74 KB FB_WWW_DEV
ReactDOMServer-dev.js +0.1% +0.2% 164.96 KB 165.18 KB 41.89 KB 41.96 KB FB_WWW_DEV
ReactDOM-prod.js 0.0% 🔺+0.1% 424.32 KB 424.53 KB 76.5 KB 76.56 KB FB_WWW_PROD
react-dom-test-utils.development.js +0.2% +0.2% 69.97 KB 70.08 KB 19.6 KB 19.64 KB NODE_DEV
ReactDOMServer-prod.js 🔺+0.3% 🔺+0.4% 53.3 KB 53.45 KB 12.85 KB 12.9 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js +2.5% +2.1% 4.42 KB 4.53 KB 1.54 KB 1.57 KB NODE_DEV
ReactDOM-profiling.js 0.0% +0.1% 435.29 KB 435.49 KB 78.41 KB 78.47 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% -0.1% 13.09 KB 13.09 KB 4.8 KB 4.8 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 56.1 KB 56.1 KB 13.84 KB 13.84 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1 KB 1 KB 610 B 609 B NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.1% 9.98 KB 9.98 KB 3.36 KB 3.35 KB UMD_PROD
ReactTestUtils-dev.js +0.3% +0.3% 65.02 KB 65.19 KB 17.51 KB 17.56 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 53.2 KB 53.2 KB 13.65 KB 13.64 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.1% 9.73 KB 9.73 KB 3.25 KB 3.25 KB NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js 0.0% 0.0% 634.43 KB 634.46 KB 133.73 KB 133.77 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 107.16 KB 107.22 KB 32.51 KB 32.53 KB UMD_PROD
react-art.development.js 0.0% 0.0% 538.72 KB 538.74 KB 116.16 KB 116.19 KB NODE_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.1% 72.15 KB 72.21 KB 21.69 KB 21.7 KB NODE_PROD
ReactART-dev.js +1.4% +1.2% 606.4 KB 614.59 KB 127.52 KB 129.03 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.1% 🔺+0.1% 251.09 KB 251.3 KB 42.67 KB 42.72 KB FB_WWW_PROD

ReactDOM: size: 0.0%, gzip: -0.0%

Size changes (stable)

Generated by 🚫 dangerJS against b44b002

@sizebot
Copy link

sizebot commented Apr 7, 2020

Details of bundled changes.

Comparing: b680174...b44b002

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-server.browser.development.js +0.1% +0.1% 162.2 KB 162.36 KB 41.21 KB 41.26 KB UMD_DEV
ReactTestUtils-dev.js +0.3% +0.3% 65.02 KB 65.19 KB 17.52 KB 17.56 KB FB_WWW_DEV
react-dom-server.browser.production.min.js 🔺+0.2% 🔺+0.2% 23.39 KB 23.44 KB 8.6 KB 8.61 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 128.5 KB 128.56 KB 40.19 KB 40.2 KB NODE_PROFILING
react-dom-unstable-fizz.browser.development.js +2.4% +2.0% 4.91 KB 5.03 KB 1.64 KB 1.68 KB UMD_DEV
ReactDOM-dev.js +0.8% +0.7% 989.59 KB 997.79 KB 220.02 KB 221.5 KB FB_WWW_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.2 KB 1.2 KB 706 B 705 B UMD_PROD
ReactDOM-prod.js 0.0% 🔺+0.1% 412.91 KB 413.12 KB 74.85 KB 74.91 KB FB_WWW_PROD
ReactDOM-profiling.js 0.0% +0.1% 423.81 KB 424.02 KB 76.72 KB 76.78 KB FB_WWW_PROFILING
react-dom-unstable-fizz.browser.development.js +2.5% +2.1% 4.43 KB 4.55 KB 1.55 KB 1.58 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1.02 KB 1.02 KB 618 B 617 B NODE_PROD
react-dom-test-utils.development.js +0.2% +0.2% 75.14 KB 75.25 KB 20.12 KB 20.15 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 13.23 KB 13.23 KB 4.9 KB 4.9 KB UMD_PROD
ReactDOMTesting-dev.js 0.0% 0.0% 932.38 KB 932.39 KB 207.89 KB 207.94 KB FB_WWW_DEV
ReactDOMTesting-prod.js 🔺+0.1% 🔺+0.1% 393.49 KB 393.69 KB 71.7 KB 71.76 KB FB_WWW_PROD
react-dom-test-utils.development.js +0.2% +0.2% 69.98 KB 70.09 KB 19.61 KB 19.64 KB NODE_DEV
ReactDOMTesting-profiling.js +0.1% +0.1% 393.49 KB 393.69 KB 71.7 KB 71.76 KB FB_WWW_PROFILING
react-dom-server.node.development.js +0.1% +0.1% 153.9 KB 154.05 KB 40.69 KB 40.75 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.1% 13.1 KB 13.1 KB 4.81 KB 4.81 KB NODE_PROD
react-dom-server.node.production.min.js 🔺+0.2% 🔺+0.3% 23.69 KB 23.73 KB 8.72 KB 8.75 KB NODE_PROD
react-dom-server.browser.development.js +0.1% +0.1% 152.68 KB 152.83 KB 40.44 KB 40.49 KB NODE_DEV
react-dom-server.browser.production.min.js 🔺+0.2% 🔺+0.4% 23.28 KB 23.32 KB 8.57 KB 8.6 KB NODE_PROD
react-dom.development.js 0.0% 0.0% 941.57 KB 941.6 KB 205.85 KB 205.88 KB UMD_DEV
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 56.11 KB 56.11 KB 13.85 KB 13.85 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 124.3 KB 124.37 KB 39.71 KB 39.73 KB UMD_PROD
ReactDOMForked-dev.js +0.8% +0.7% 989.61 KB 997.81 KB 220.17 KB 221.66 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.1% 10 KB 10 KB 3.36 KB 3.36 KB UMD_PROD
ReactDOMServer-dev.js +0.1% +0.2% 161.46 KB 161.68 KB 40.99 KB 41.05 KB FB_WWW_DEV
react-dom.profiling.min.js 0.0% +0.1% 128.15 KB 128.21 KB 40.93 KB 40.95 KB UMD_PROFILING
ReactDOMForked-prod.js 0.0% 🔺+0.1% 413.48 KB 413.69 KB 74.93 KB 74.99 KB FB_WWW_PROD
ReactDOMServer-prod.js 🔺+0.3% 🔺+0.4% 52.57 KB 52.72 KB 12.68 KB 12.73 KB FB_WWW_PROD
react-dom.development.js 0.0% 0.0% 896.51 KB 896.53 KB 203.35 KB 203.4 KB NODE_DEV
ReactDOMForked-profiling.js 0.0% +0.1% 424.38 KB 424.59 KB 76.82 KB 76.89 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 53.21 KB 53.21 KB 13.65 KB 13.65 KB NODE_DEV
react-dom-unstable-fizz.node.development.js +2.2% +2.0% 5.18 KB 5.29 KB 1.7 KB 1.73 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 124.5 KB 124.56 KB 38.95 KB 38.97 KB NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.1% 9.75 KB 9.75 KB 3.26 KB 3.25 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.17 KB 1.17 KB 668 B 667 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js 0.0% 0.0% 658.56 KB 658.59 KB 138.52 KB 138.56 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 0.0% 110.44 KB 110.5 KB 33.43 KB 33.45 KB UMD_PROD
react-art.development.js 0.0% 0.0% 561.85 KB 561.87 KB 120.99 KB 121.02 KB NODE_DEV
react-art.production.min.js 🔺+0.1% 0.0% 75.39 KB 75.45 KB 22.67 KB 22.68 KB NODE_PROD
ReactART-dev.js +1.4% +1.2% 596.33 KB 604.53 KB 125.52 KB 126.99 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.1% 🔺+0.1% 243.64 KB 243.85 KB 41.43 KB 41.47 KB FB_WWW_PROD

ReactDOM: size: 🔺+0.2%, gzip: 🔺+0.2%

Size changes (experimental)

Generated by 🚫 dangerJS against b44b002

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 7, 2020

Don't care about failing CI right now, just trying out an idea.

enableDebugTracing feature flag still turns this feature on and off, but now React won't auto-log anything (e.g. state updates, suspends) unless it's within a <React.DebugTraceMode> subtree.

Maybe this helps cut down on the (unrelated?) noise a bit from clients like Comet who have a lot of logs.

Edit It's kind of neat playing around with this on Comet, scoping my logs to e.g. the Notifications dropdown.

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 10, 2020

Rebased and added to old/new variants.

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Let's get this in and we can iterate later. (Assuming we make it completely invisible in prod and non-flagged builds.)

I want to get it in because I need it every other week but by that point PR is stale and I can't use it anymore.

packages/react-is/src/ReactIs.js Outdated Show resolved Hide resolved
@@ -488,6 +490,10 @@ export function createFiberFromTypeAndProps(
expirationTime,
key,
);
case REACT_DEBUG_TRACE_MODE_TYPE:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any way to make this branch DEV-only, and fall through to unknown case otherwise?

Copy link
Contributor Author

@bvaughn bvaughn Apr 15, 2020

Choose a reason for hiding this comment

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

Hm... well... we could fork the entire switch statement, but that doesn't seem good.

We could maybe...also pre-filter type, e.g.

let filteredType = type;
if (!__DEV__ && type === REACT_DEBUG_TRACE_MODE_TYPE) {
  filteredType = null;
}

But neither of those really feel like improvements.

That being said, if I just conditionally export DebugTraceMode as undefined in non-DEV mode it shouldn't be reachable anyway.

packages/react-reconciler/src/ReactTypeOfMode.js Outdated Show resolved Hide resolved
packages/react/src/React.js Outdated Show resolved Hide resolved
packages/react/index.js Outdated Show resolved Hide resolved
packages/shared/ReactSymbols.js Outdated Show resolved Hide resolved
@gaearon
Copy link
Collaborator

gaearon commented Apr 14, 2020

Also need to fix SSR to pass it through.

@gaearon
Copy link
Collaborator

gaearon commented Apr 15, 2020

This is also missing a crucial feature: tracking of Promises. I think it's an easy fix.

Here's what I hacked together:

let wakeableIDs = new WeakMap();
let id = 0;
function getWakeableID(wakeable) {
  if (!wakeableIDs.has(wakeable)) {
    wakeableIDs.set(wakeable, id++);
  }
  return wakeableIDs.get(wakeable);
}

function logComponentSuspended(componentName, wakeable) {
  log(
    '[!] + ' + componentName + " suspended",
    getWakeableID(wakeable),
    wakeable.displayName,
  );
  wakeable.then(() => {
    log('[!] Promise fulfilled',
      getWakeableID(wakeable),
      wakeable.displayName,
    )
  }, () => {
    log('[!] Promise rejected',
      getWakeableID(wakeable),
      wakeable.displayName,
    )
  })
}

Without this I can't tell whether something is a React or a Relay bug.

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 15, 2020

function logComponentSuspended(componentName, wakeable) {
  log(
    '[!] + ' + componentName + " suspended",
    getWakeableID(wakeable),
    wakeable.displayName,
  );
  wakeable.then(() => {
    log('[!] Promise fulfilled',
      getWakeableID(wakeable),
      wakeable.displayName,
    )
  }, () => {
    log('[!] Promise rejected',
      getWakeableID(wakeable),
      wakeable.displayName,
    )
  })
}

Wakeables have displayNames? 😮 😕

Sure I can add resolve/reject tracing

* Removed "render scheduled" message; it was the only one outside of the <Mode> and just didn't feel worth the added noise.
* Added SSR pass through (and tests)
* Add promise resolution/rejection logging
* Removed debug mode from "react-is" package
* Export  for the symbol if the feature flag is off
@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 15, 2020

Ok, back to you!

@bvaughn bvaughn marked this pull request as ready for review April 15, 2020 22:06
@gaearon
Copy link
Collaborator

gaearon commented Apr 15, 2020

Wakeables have displayNames? 😮 😕

Just the Relay ones. :D

@gaearon
Copy link
Collaborator

gaearon commented Apr 15, 2020

What's up with tests?

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 15, 2020

What's up with tests?

I don't know. I still don't have a good understanding of how all of our various test combinations run and how to satisfy each of them I guess. I'll look into it...

Edit Not sure why my change would cause failures in other tests. Some of the Yarn commands + test targets that failed on CI work for me locally... Going to just try re-running them.

@@ -39,6 +39,53 @@ describe('ReactDOMServerIntegration', () => {
resetModules();
});

// Test pragmas don't support itRenders abstraction
if (require('shared/ReactFeatureFlags').enableDebugTracing) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we align feature flag closer to component name? One way or another. I keep mistyping either of them because "trace" vs "tracing". :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, yeah sure thing

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 16, 2020

What's up with tests?

I'm not sure why but the test failure seems to have been caused by the conditional I added to ReactSymbols --- presumably related to importing ReactFeatureFlags from that file? I'm not sure. For now, I just backed that change out.

@@ -488,6 +490,10 @@ export function createFiberFromTypeAndProps(
expirationTime,
key,
);
case REACT_DEBUG_TRACING_MODE_TYPE:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it mean that if I somehow end up with undefined type in a stable release, after this change it would start matching REACT_DEBUG_TRACING_MODE_TYPE (which would also be undefined in stable), and thus I won't get to the catch-all default case that throws? This seems bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

REACT_DEBUG_TRACING_MODE_TYPE isn't undefined in stable, just React.DebugTracingMode.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(I backed out the conditional symbol export)

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

I'm still a bit confused about the plan for not shipping it in a stable release. I think currently the export would appear on React object.

Making the internal constant itself undefined wouldn't work because you don't want to match all the cases to undefined. But you can make the export from React package conditionally undefined. I also think the export should be prefixed with unstable_ in case we mess up the flags or it becomes enumerable.

packages/react-reconciler/src/ReactFiberWorkLoop.new.js Outdated Show resolved Hide resolved
packages/react-reconciler/src/ReactFiberWorkLoop.old.js Outdated Show resolved Hide resolved
@@ -59,6 +59,7 @@ export {
createMutableSource,
Fragment,
Profiler,
DebugTracingMode,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it become enumerable (but undefined) export? If yes, it should be unstable_.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will never be undefined. It's just not re-exported by the .stable index. (This index file itself is never used directly.)

@@ -11,6 +11,7 @@ import typeof * as FeatureFlagsType from 'shared/ReactFeatureFlags';
import typeof * as ExportsType from './ReactFeatureFlags.testing.www';

export const debugRenderPhaseSideEffectsForStrictMode = false;
export const enableDebugTracing = __EXPERIMENTAL__;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's just make it false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hopefully that won't make the test matrix gods angry.

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Chatted in messenger. Looks good but let's rename export to unstable_ anyway.

@gaearon gaearon changed the title Debug logging [wip] Add experimental DebugTracing logger for internal use Apr 16, 2020
@bvaughn bvaughn merged commit 22dc2e4 into facebook:master Apr 16, 2020
@bvaughn bvaughn deleted the debug-logging branch April 16, 2020 02:10
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.

5 participants