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

Allow arbitrary types to be wrapped in pure #13903

Merged
merged 2 commits into from
Oct 20, 2018

Conversation

sebmarkbage
Copy link
Collaborator

First I made the PureComponent a slow path. This creates an outer fiber that container the pure check and an inner fiber that represents which ever type of component.

Then I added an optimized fast path for simple pure function components. This is special cased when there are no defaultProps and it's a simple function component instead of class. This doesn't require an extra fiber.

We could make it so that this also works with custom comparer but that means we have to go through one extra indirection to get to it. Maybe it's worth it, donno.

This creates an outer fiber that container the pure check and an inner
fiber that represents which ever type of component.
Special cased when there are no defaultProps and it's a simple function
component instead of class. This doesn't require an extra fiber.

We could make it so that this also works with custom comparer but that
means we have to go through one extra indirection to get to it.
Maybe it's worth it, donno.
@sizebot
Copy link

sizebot commented Oct 20, 2018

React: size: -0.0%, gzip: -0.0%

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

Details of bundled changes.

Comparing: e770af7...a3c5827

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js -0.3% -0.2% 94.03 KB 93.72 KB 24.73 KB 24.68 KB UMD_DEV
react.production.min.js -0.0% -0.0% 11.69 KB 11.69 KB 4.62 KB 4.62 KB UMD_PROD
react.development.js -0.5% -0.3% 56.74 KB 56.43 KB 15.24 KB 15.2 KB NODE_DEV
react.production.min.js -0.0% -0.1% 6.11 KB 6.11 KB 2.6 KB 2.6 KB NODE_PROD
React-dev.js -0.6% -0.4% 53.11 KB 52.77 KB 14.4 KB 14.34 KB FB_WWW_DEV
React-prod.js -0.0% -0.1% 13.95 KB 13.94 KB 3.82 KB 3.82 KB FB_WWW_PROD
React-profiling.js -0.0% -0.1% 13.95 KB 13.94 KB 3.82 KB 3.82 KB FB_WWW_PROFILING
react.profiling.min.js -0.0% 0.0% 13.85 KB 13.84 KB 5.14 KB 5.14 KB UMD_PROFILING

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.3% +0.2% 675.57 KB 677.28 KB 157.09 KB 157.47 KB UMD_DEV
react-dom.production.min.js 🔺+0.4% 🔺+0.4% 97.23 KB 97.62 KB 31.8 KB 31.92 KB UMD_PROD
react-dom.development.js +0.3% +0.2% 670.91 KB 672.62 KB 155.7 KB 156.08 KB NODE_DEV
react-dom.production.min.js 🔺+0.4% 🔺+0.3% 97.25 KB 97.63 KB 31.36 KB 31.46 KB NODE_PROD
react-dom-server.browser.development.js -0.0% -0.0% 107.64 KB 107.63 KB 28.54 KB 28.54 KB UMD_DEV
react-dom-server.browser.production.min.js -0.2% -0.2% 15.79 KB 15.75 KB 6.03 KB 6.02 KB UMD_PROD
react-dom-server.browser.development.js -0.0% 0.0% 103.77 KB 103.76 KB 27.54 KB 27.54 KB NODE_DEV
react-dom-server.browser.production.min.js -0.2% -0.1% 15.68 KB 15.65 KB 6.02 KB 6.01 KB NODE_PROD
react-dom-server.node.development.js -0.0% -0.0% 105.69 KB 105.68 KB 28.1 KB 28.1 KB NODE_DEV
react-dom-server.node.production.min.js -0.2% -0.2% 16.49 KB 16.46 KB 6.32 KB 6.31 KB NODE_PROD
ReactDOM-dev.js +0.3% +0.3% 688.86 KB 690.82 KB 156.37 KB 156.78 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.5% 🔺+0.5% 293.64 KB 295.22 KB 53.87 KB 54.11 KB FB_WWW_PROD
ReactDOMServer-dev.js -0.0% -0.0% 103.3 KB 103.29 KB 26.83 KB 26.83 KB FB_WWW_DEV
ReactDOMServer-prod.js -0.2% -0.4% 34.56 KB 34.48 KB 8.34 KB 8.3 KB FB_WWW_PROD
react-dom.profiling.min.js +0.4% +0.4% 99.65 KB 100.03 KB 31.72 KB 31.84 KB NODE_PROFILING
ReactDOM-profiling.js +0.5% +0.5% 298.14 KB 299.73 KB 54.94 KB 55.19 KB FB_WWW_PROFILING
react-dom.profiling.min.js +0.4% +0.4% 99.58 KB 99.97 KB 32.21 KB 32.33 KB UMD_PROFILING

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.4% +0.4% 463.03 KB 464.72 KB 102.9 KB 103.29 KB UMD_DEV
react-art.production.min.js 🔺+0.4% 🔺+0.5% 89.19 KB 89.58 KB 27.44 KB 27.56 KB UMD_PROD
react-art.development.js +0.4% +0.4% 394.8 KB 396.51 KB 85.82 KB 86.2 KB NODE_DEV
react-art.production.min.js 🔺+0.7% 🔺+0.7% 54.16 KB 54.55 KB 16.72 KB 16.84 KB NODE_PROD
ReactART-dev.js +0.5% +0.5% 399.12 KB 401.08 KB 84.25 KB 84.67 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.9% 🔺+1.0% 166.92 KB 168.5 KB 28.21 KB 28.48 KB FB_WWW_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.4% +0.4% 407.47 KB 409.21 KB 88.56 KB 88.95 KB UMD_DEV
react-test-renderer.production.min.js 🔺+0.7% 🔺+0.5% 55.34 KB 55.73 KB 17.1 KB 17.19 KB UMD_PROD
react-test-renderer.development.js +0.4% +0.4% 403.05 KB 404.79 KB 87.46 KB 87.85 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.7% 🔺+0.5% 55.06 KB 55.45 KB 16.85 KB 16.94 KB NODE_PROD
react-test-renderer-shallow.development.js -0.1% -0.0% 26.66 KB 26.64 KB 7.17 KB 7.16 KB UMD_DEV
react-test-renderer-shallow.development.js -0.1% 0.0% 21.16 KB 21.14 KB 5.74 KB 5.74 KB NODE_DEV
react-test-renderer-shallow.production.min.js -0.4% -0.3% 7.99 KB 7.96 KB 2.65 KB 2.64 KB NODE_PROD
ReactTestRenderer-dev.js +0.5% +0.5% 407.74 KB 409.72 KB 86.25 KB 86.67 KB FB_WWW_DEV
ReactShallowRenderer-dev.js -0.1% -0.0% 18.14 KB 18.13 KB 4.74 KB 4.74 KB FB_WWW_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.4% +0.4% 392.5 KB 394.21 KB 84.27 KB 84.65 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.7% 🔺+0.7% 55.2 KB 55.59 KB 16.55 KB 16.67 KB NODE_PROD
react-reconciler-persistent.development.js +0.4% +0.5% 391.11 KB 392.82 KB 83.71 KB 84.09 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.7% 🔺+0.7% 55.21 KB 55.6 KB 16.56 KB 16.68 KB NODE_PROD
react-reconciler-reflection.development.js -0.1% 0.0% 16.37 KB 16.36 KB 4.96 KB 4.96 KB NODE_DEV

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.4% +0.4% 525.74 KB 527.7 KB 115.21 KB 115.62 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.7% 🔺+0.6% 221.67 KB 223.25 KB 38.57 KB 38.81 KB RN_FB_PROD
ReactNativeRenderer-dev.js +0.4% +0.4% 525.45 KB 527.41 KB 115.14 KB 115.54 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.7% 🔺+0.6% 221.68 KB 223.27 KB 38.57 KB 38.81 KB RN_OSS_PROD
ReactFabric-dev.js +0.4% +0.4% 515.97 KB 517.92 KB 112.8 KB 113.2 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.7% 🔺+0.6% 216.24 KB 217.82 KB 37.28 KB 37.52 KB RN_FB_PROD
ReactFabric-dev.js +0.4% +0.4% 516 KB 517.96 KB 112.81 KB 113.22 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.7% 🔺+0.6% 216.28 KB 217.86 KB 37.29 KB 37.53 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.7% +0.6% 227.38 KB 228.97 KB 39.92 KB 40.16 KB RN_OSS_PROFILING
ReactFabric-profiling.js +0.7% +0.6% 221.12 KB 222.7 KB 38.58 KB 38.82 KB RN_OSS_PROFILING
ReactNativeRenderer-profiling.js +0.7% +0.6% 227.37 KB 228.95 KB 39.92 KB 40.16 KB RN_FB_PROFILING
ReactFabric-profiling.js +0.7% +0.6% 221.08 KB 222.66 KB 38.56 KB 38.8 KB RN_FB_PROFILING

scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
scheduler.development.js n/a n/a 0 B 19.17 KB 0 B 5.74 KB UMD_DEV
scheduler.production.min.js n/a n/a 0 B 3.16 KB 0 B 1.53 KB UMD_PROD

Generated by 🚫 dangerJS

expect(renderCount).toBe(3);
});

it('should custom pure comparisons to compose', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing a word?

@sebmarkbage sebmarkbage merged commit 15b11d2 into facebook:master Oct 20, 2018
linjiajian999 pushed a commit to linjiajian999/react that referenced this pull request Oct 22, 2018
* Allow arbitrary types to be wrapped in pure

This creates an outer fiber that container the pure check and an inner
fiber that represents which ever type of component.

* Add optimized fast path for simple pure function components

Special cased when there are no defaultProps and it's a simple function
component instead of class. This doesn't require an extra fiber.

We could make it so that this also works with custom comparer but that
means we have to go through one extra indirection to get to it.
Maybe it's worth it, donno.
jetoneza pushed a commit to jetoneza/react that referenced this pull request Jan 23, 2019
* Allow arbitrary types to be wrapped in pure

This creates an outer fiber that container the pure check and an inner
fiber that represents which ever type of component.

* Add optimized fast path for simple pure function components

Special cased when there are no defaultProps and it's a simple function
component instead of class. This doesn't require an extra fiber.

We could make it so that this also works with custom comparer but that
means we have to go through one extra indirection to get to it.
Maybe it's worth it, donno.
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
* Allow arbitrary types to be wrapped in pure

This creates an outer fiber that container the pure check and an inner
fiber that represents which ever type of component.

* Add optimized fast path for simple pure function components

Special cased when there are no defaultProps and it's a simple function
component instead of class. This doesn't require an extra fiber.

We could make it so that this also works with custom comparer but that
means we have to go through one extra indirection to get to it.
Maybe it's worth it, donno.
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