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

Slightly improve performance of hydration. #15998

Merged
merged 3 commits into from
Jun 27, 2019

Conversation

bmeurer
Copy link
Contributor

@bmeurer bmeurer commented Jun 26, 2019

Avoid loading nodeType and data couple times from the same node in a row,
but instead load them only once, which will help engines to run this code
faster, especially during startup of the application. The general approach
is still not ideal, since hydrating this way forces the browser engine
to materialize JavaScript wrapper objects for all DOM nodes, even if they
are not interesting to hydration itself.

Avoid loading nodeType and data couple times from the same node in a row,
but instead load them only once, which will help engines to run this code
faster, especially during startup of the application. The general approach
is still not ideal, since hydrating this way forces the browser engine
to materialize JavaScript wrapper objects for all DOM nodes, even if they
are not interesting to hydration itself.
@sizebot
Copy link

sizebot commented Jun 26, 2019

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

Details of bundled changes.

Comparing: 9b55bcf...fba82af

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js -0.0% -0.0% 114.17 KB 114.14 KB 36.04 KB 36.03 KB NODE_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.76 KB 60.76 KB 15.85 KB 15.84 KB UMD_DEV
ReactDOM-dev.js -0.0% -0.0% 922.95 KB 922.75 KB 204.53 KB 204.5 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.1% 10.74 KB 10.74 KB 3.68 KB 3.68 KB UMD_PROD
ReactDOMServer-dev.js 0.0% -0.0% 136.28 KB 136.28 KB 34.9 KB 34.9 KB FB_WWW_DEV
react-dom-unstable-fire.development.js -0.0% -0.0% 899.54 KB 899.41 KB 204.2 KB 204.18 KB UMD_DEV
react-dom-unstable-fire.production.min.js -0.0% -0.0% 110.58 KB 110.54 KB 35.6 KB 35.6 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js -0.0% -0.0% 113.91 KB 113.87 KB 36.64 KB 36.63 KB UMD_PROFILING
react-dom-unstable-fire.development.js -0.0% -0.0% 893.83 KB 893.7 KB 202.69 KB 202.67 KB NODE_DEV
react-dom-server.node.development.js 0.0% -0.0% 135.54 KB 135.54 KB 35.85 KB 35.85 KB NODE_DEV
react-dom-unstable-fire.production.min.js -0.0% -0.0% 110.66 KB 110.62 KB 35.16 KB 35.16 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% -0.0% 20.23 KB 20.23 KB 7.58 KB 7.57 KB NODE_PROD
react-dom.development.js -0.0% -0.0% 899.19 KB 899.06 KB 204.06 KB 204.03 KB UMD_DEV
react-dom-unstable-fire.profiling.min.js -0.0% -0.0% 114.19 KB 114.15 KB 36.05 KB 36.04 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 137.48 KB 137.48 KB 36.25 KB 36.24 KB UMD_DEV
react-dom.production.min.js -0.0% -0.0% 110.57 KB 110.53 KB 35.59 KB 35.59 KB UMD_PROD
ReactFire-dev.js -0.0% -0.0% 922.16 KB 921.96 KB 204.41 KB 204.39 KB FB_WWW_DEV
react-dom.profiling.min.js -0.0% -0.0% 113.89 KB 113.86 KB 36.63 KB 36.62 KB UMD_PROFILING
ReactFire-prod.js -0.1% -0.1% 363.51 KB 363.08 KB 66.43 KB 66.36 KB FB_WWW_PROD
react-dom.development.js -0.0% -0.0% 893.49 KB 893.36 KB 202.55 KB 202.52 KB NODE_DEV
ReactFire-profiling.js -0.1% -0.1% 370.38 KB 369.96 KB 67.74 KB 67.67 KB FB_WWW_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 133.61 KB 133.61 KB 35.31 KB 35.3 KB NODE_DEV
react-dom.production.min.js -0.0% -0.0% 110.64 KB 110.61 KB 35.15 KB 35.15 KB NODE_PROD
react-dom-server.browser.production.min.js 0.0% -0.0% 19.38 KB 19.38 KB 7.28 KB 7.28 KB NODE_PROD
ReactDOM-prod.js -0.1% -0.1% 375.53 KB 375.1 KB 68.82 KB 68.76 KB FB_WWW_PROD
ReactDOMServer-prod.js 0.0% -0.0% 48.36 KB 48.36 KB 11.12 KB 11.12 KB FB_WWW_PROD
ReactDOM-profiling.js -0.1% -0.1% 382.44 KB 382.01 KB 70.14 KB 70.08 KB FB_WWW_PROFILING
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-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-native-dependencies.production.min.js 0.0% -0.1% 10.48 KB 10.48 KB 3.58 KB 3.58 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% -0.2% 1.1 KB 1.1 KB 666 B 665 B NODE_PROD
react-dom-test-utils.development.js 0.0% -0.0% 57.84 KB 57.84 KB 15.88 KB 15.88 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.2% 3.81 KB 3.81 KB 1.54 KB 1.53 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.95 KB 10.95 KB 4 KB 4 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.3% 1.21 KB 1.21 KB 705 B 703 B UMD_PROD
react-dom-test-utils.development.js 0.0% -0.0% 56.11 KB 56.11 KB 15.55 KB 15.55 KB NODE_DEV
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-test-utils.production.min.js 0.0% 0.0% 10.7 KB 10.7 KB 3.94 KB 3.94 KB NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1.05 KB 1.05 KB 636 B 635 B NODE_PROD

Generated by 🚫 dangerJS

@aweary aweary requested review from sebmarkbage and gaearon and removed request for sebmarkbage June 27, 2019 03:12
@sebmarkbage
Copy link
Collaborator

In normal usage, it is not expected that there will be any non-hydratable nodes. So these would all be materialized anyway. This is here mostly as a precaution against browser extensions or proxies inserting unexpected content.

@sebmarkbage sebmarkbage merged commit 915dfe6 into facebook:master Jun 27, 2019
@bmeurer bmeurer deleted the DOM_Accessors branch June 27, 2019 14:36
@bmeurer
Copy link
Contributor Author

bmeurer commented Jun 27, 2019

Thanks. I'm wondering if it's possible to do something about this in general. While it's probably possible to optimize this a bit more with the current approach, having to materialize all these wrapper objects is always gonna remain a bottleneck.

cc @developit @ timneutkens

@sebmarkbage
Copy link
Collaborator

One thing we could do is drop all validation but still preresolve references to the node. Is there a way to walk the DOM while not materializing JS wrappers or cheaper ones?

We used to have a lazy approach but that instead paid the cost when the user interacted with something and also added complexity and meta-data that made it overall not worth it.

We’re moving to a selective hydration approach driven by interaction which effectively makes the paths lazy but also able to warm up in preparation for an interaction. So the characteristics are about to change.

@bmeurer
Copy link
Contributor Author

bmeurer commented Jun 27, 2019

Interesting. The lazy approach sounds like a viable path.

Not validating, i.e. not loading nodeType and doing these lower case comparisons can probably reduce worst case scenarios - where we right not have easily 600ms for hydration - significantly.

}
if (enableSuspenseServerRenderer) {
if (nodeType === COMMENT_NODE) {
break;
Copy link
Collaborator

@sebmarkbage sebmarkbage Aug 4, 2019

Choose a reason for hiding this comment

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

This should actually have been if (nodeType !== COMMENT_NODE) continue. Logic is hard. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, test coverage is hard :D

This was referenced Mar 10, 2020
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.

5 participants