Skip to content

Commit

Permalink
Merge branch 'next' into feat/new-bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Oct 12, 2020
2 parents 92f8719 + a4a4476 commit d565045
Show file tree
Hide file tree
Showing 32 changed files with 751 additions and 1,221 deletions.
3 changes: 0 additions & 3 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ update_configs:
- match:
# should be grouped with `react`
dependency_name: 'react-test-renderer'
- match:
# breaks `yarn size:why`
dependency_name: 'size-limit'
- match:
# https://github.com/mui-org/material-ui/pull/17168#issuecomment-524861427
dependency_name: 'tslint'
Expand Down
11 changes: 11 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Browser benchmark

This project is used when running the following command:

```sh
yarn benchmark
```

It is suppose to give developers comparable values between running different scenarios inside the browser, that can be find the `./scenarios` folder.

You should use these numbers exclusively for comparing performance between different scenarios, not as absolute values. There is also a `./noop` scenario, that renders nothing, to give you the idea of the initial setup time before the actual code is being run.
13 changes: 13 additions & 0 deletions benchmark/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Perf scenario</title>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, width=device-width" />
<style>body { background-color: white; }</style>
</head>
<body>
<div id="root"></div>
<script src="../../tmp/benchmark.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions benchmark/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';

// Get all the scenarios
const requirePerfScenarios = require.context('./scenarios', true, /(js|ts|tsx)$/);

const rootEl = document.getElementById('root');

const scenarioSuitePath = window.location.search.replace('?', '');

const Component = requirePerfScenarios(scenarioSuitePath).default;

const start = performance.now();
let end;

function TestCase(props) {
const ref = React.useRef(null);

React.useLayoutEffect(() => {
// Force layout
ref.current.getBoundingClientRect();

end = performance.now();
window.timing = {
render: end - start,
};
});

return <div ref={ref}>{props.children}</div>;
}

TestCase.propTypes = {
children: PropTypes.node,
};

ReactDOM.render(
<TestCase>
<Component />
</TestCase>,
rootEl,
);
29 changes: 29 additions & 0 deletions benchmark/scenarios/box-emotion/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import { createMuiTheme } from '@material-ui/core/styles';
import styledEmotion from '@emotion/styled';
import { ThemeProvider as EmotionTheme } from 'emotion-theming';
import { styleFunction } from '@material-ui/core/Box';
import { logReactMetrics } from '../utils';

const materialSystemTheme = createMuiTheme();
const Box = styledEmotion('div')(styleFunction);

export default function BoxEmotion() {
return (
<React.Profiler id="box-emotion" onRender={logReactMetrics}>
{new Array(1000).fill().map(() => (
<EmotionTheme theme={materialSystemTheme}>
<Box
color="primary.main"
bgcolor="background.paper"
fontFamily="h6.fontFamily"
fontSize={['h6.fontSize', 'h4.fontSize', 'h3.fontSize']}
p={[2, 3, 4]}
>
emotion
</Box>
</EmotionTheme>
))}
</React.Profiler>
);
}
27 changes: 27 additions & 0 deletions benchmark/scenarios/box-material-ui-styles/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import { createMuiTheme } from '@material-ui/core/styles';
import { ThemeProvider as StylesThemeProvider } from '@material-ui/styles';
import BoxStyles from '@material-ui/core/Box';
import { logReactMetrics } from '../utils';

const materialSystemTheme = createMuiTheme();

export default function BoxMaterialUIStyles() {
return (
<React.Profiler id="box-material-ui-system" onRender={logReactMetrics}>
{new Array(1000).fill().map(() => (
<StylesThemeProvider theme={materialSystemTheme}>
<BoxStyles
color="primary.main"
bgcolor="background.paper"
fontFamily="h6.fontFamily"
fontSize={['h6.fontSize', 'h4.fontSize', 'h3.fontSize']}
p={[2, 3, 4]}
>
@material-ui/styles
</BoxStyles>
</StylesThemeProvider>
))}
</React.Profiler>
);
}
30 changes: 30 additions & 0 deletions benchmark/scenarios/box-styled-components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import { createMuiTheme } from '@material-ui/core/styles';
import { styleFunction } from '@material-ui/core/Box';
import styledComponents, {
ThemeProvider as StyledComponentsThemeProvider,
} from 'styled-components';
import { logReactMetrics } from '../utils';

const materialSystemTheme = createMuiTheme();
const BoxStyleComponents = styledComponents('div')(styleFunction);

export default function BoxStyledComponents() {
return (
<React.Profiler id="box-styled-components" onRender={logReactMetrics}>
{new Array(1000).fill().map(() => (
<StyledComponentsThemeProvider theme={materialSystemTheme}>
<BoxStyleComponents
color="primary.main"
bgcolor="background.paper"
fontFamily="h6.fontFamily"
fontSize={['h6.fontSize', 'h4.fontSize', 'h3.fontSize']}
p={[2, 3, 4]}
>
styled-components
</BoxStyleComponents>
</StyledComponentsThemeProvider>
))}
</React.Profiler>
);
}
17 changes: 17 additions & 0 deletions benchmark/scenarios/material-ui-system-all-inclusive/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createMuiTheme } from '@material-ui/core/styles';
import { styleFunction } from '@material-ui/core/Box';

const materialSystemTheme = createMuiTheme();

export default function MaterialUISystemAllInclusive() {
styleFunction({
theme: materialSystemTheme,
color: 'primary.main',
bgcolor: 'background.paper',
fontFamily: 'h6.fontFamily',
fontSize: ['h6.fontSize', 'h4.fontSize', 'h3.fontSize'],
p: [2, 3, 4],
});

return null;
}
10 changes: 10 additions & 0 deletions benchmark/scenarios/material-ui-system-colors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { palette } from '@material-ui/system';

export default function MaterialUISystemColors() {
palette({
theme: {},
bgcolor: ['red', 'blue'],
});

return null;
}
18 changes: 18 additions & 0 deletions benchmark/scenarios/material-ui-system-compose/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createMuiTheme } from '@material-ui/core/styles';
import { spacing, palette, typography, compose } from '@material-ui/system';

const materialSystem = compose(palette, spacing, typography);
const materialSystemTheme = createMuiTheme();

export default function MaterialUISystemCompose() {
materialSystem({
theme: materialSystemTheme,
color: 'primary.main',
bgcolor: 'background.paper',
fontFamily: 'h6.fontFamily',
fontSize: ['h6.fontSize', 'h4.fontSize', 'h3.fontSize'],
p: [2, 3, 4],
});

return null;
}
10 changes: 10 additions & 0 deletions benchmark/scenarios/material-ui-system-spaces/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { spacing } from '@material-ui/system';

export default function MaterialUISystemSpaces() {
spacing({
theme: {},
p: [1, 2, 3],
});

return null;
}
30 changes: 30 additions & 0 deletions benchmark/scenarios/naked-styled-components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as React from 'react';
import { createMuiTheme } from '@material-ui/core/styles';
import { spacing } from '@material-ui/system';
import styledComponents, {
ThemeProvider as StyledComponentsThemeProvider,
} from 'styled-components';
import { logReactMetrics } from '../utils';

const materialSystemTheme = createMuiTheme();
const NakedStyleComponents = styledComponents('div')(spacing);

export default function NakedStyledComponents() {
return (
<React.Profiler id="naked-styled-components" onRender={logReactMetrics}>
{new Array(1000).fill().map(() => (
<StyledComponentsThemeProvider theme={materialSystemTheme}>
<NakedStyleComponents
color="primary.main"
bgcolor="background.paper"
fontFamily="h6.fontFamily"
fontSize={['h6.fontSize', 'h4.fontSize', 'h3.fontSize']}
p={[2, 3, 4]}
>
styled-components
</NakedStyleComponents>
</StyledComponentsThemeProvider>
))}
</React.Profiler>
);
}
3 changes: 3 additions & 0 deletions benchmark/scenarios/noop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Noop() {
return null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import { createMuiTheme } from '@material-ui/core/styles';
import styledComponents, {
ThemeProvider as StyledComponentsThemeProvider,
} from 'styled-components';
import { spacing, palette, typography, compose } from '@material-ui/system';
import { logReactMetrics } from '../utils';

const materialSystem = compose(palette, spacing, typography);
const materialSystemTheme = createMuiTheme();
const BoxMaterialSystem = styledComponents('div')(materialSystem);

export default function StyledComponentsBoxMaterialUISystem() {
return (
<React.Profiler id="styled-components-box-material-ui-system" onRender={logReactMetrics}>
{new Array(1000).fill().map(() => (
<StyledComponentsThemeProvider theme={materialSystemTheme}>
<BoxMaterialSystem
color="primary.main"
bgcolor="background.paper"
fontFamily="h6.fontFamily"
fontSize={['h6.fontSize', 'h4.fontSize', 'h3.fontSize']}
p={[2, 3, 4]}
>
@material-ui/system
</BoxMaterialSystem>
</StyledComponentsThemeProvider>
))}
</React.Profiler>
);
}
36 changes: 36 additions & 0 deletions benchmark/scenarios/styled-components-box-styled-system/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as React from 'react';
import { createMuiTheme } from '@material-ui/core/styles';
import styledComponents, {
ThemeProvider as StyledComponentsThemeProvider,
} from 'styled-components';
import { space, color, fontFamily, fontSize, compose } from 'styled-system';
import { logReactMetrics } from '../utils';

const styledSystem = compose(color, space, fontFamily, fontSize);
const BoxStyledSystem = styledComponents('div')(styledSystem);

const styledSystemTheme = createMuiTheme();
styledSystemTheme.breakpoints = ['40em', '52em', '64em'];
styledSystemTheme.colors = styledSystemTheme.palette;
styledSystemTheme.fontSizes = styledSystemTheme.typography;
styledSystemTheme.fonts = styledSystemTheme.typography;

export default function StyledComponentsBoxStyledSystem() {
return (
<React.Profiler id="styled-components-box-styled-system" onRender={logReactMetrics}>
{new Array(1000).fill().map(() => (
<StyledComponentsThemeProvider theme={styledSystemTheme}>
<BoxStyledSystem
color="primary.main"
bg="background.paper"
fontFamily="h6.fontFamily"
fontSize={['h6.fontSize', 'h4.fontSize', 'h3.fontSize']}
p={[2, 3, 4]}
>
styled-system
</BoxStyledSystem>
</StyledComponentsThemeProvider>
))}
</React.Profiler>
);
}
10 changes: 10 additions & 0 deletions benchmark/scenarios/styled-system-colors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { color } from 'styled-system';

export default function StyledSystemColors() {
color({
theme: {},
bg: ['red', 'blue'],
});

return null;
}
22 changes: 22 additions & 0 deletions benchmark/scenarios/styled-system-compose/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createMuiTheme } from '@material-ui/core/styles';
import { space, color, fontFamily, fontSize, compose } from 'styled-system';

const styledSystem = compose(color, space, fontFamily, fontSize);
const styledSystemTheme = createMuiTheme();
styledSystemTheme.breakpoints = ['40em', '52em', '64em'];
styledSystemTheme.colors = styledSystemTheme.palette;
styledSystemTheme.fontSizes = styledSystemTheme.typography;
styledSystemTheme.fonts = styledSystemTheme.typography;

export default function StyledSystemCompose() {
styledSystem({
theme: styledSystemTheme,
color: 'primary.main',
bg: 'background.paper',
fontFamily: 'h6.fontFamily',
fontSize: ['h6.fontSize', 'h4.fontSize', 'h3.fontSize'],
p: [2, 3, 4],
});

return null;
}
10 changes: 10 additions & 0 deletions benchmark/scenarios/styled-system-spaces/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { space } from 'styled-system';

export default function StyledSystemSpaces() {
space({
theme: {},
p: [1, 2, 3],
});

return null;
}
22 changes: 22 additions & 0 deletions benchmark/scenarios/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable import/prefer-default-export */

export const logReactMetrics = (
id, // the "id" prop of the Profiler tree that has just committed
phase, // either "mount" (if the tree just mounted) or "update" (if it re-rendered)
actualDuration, // time spent rendering the committed update
baseDuration, // estimated time to render the entire subtree without memoization
startTime, // when React began rendering this update
commitTime, // when React committed this update
interactions, // the Set of interactions belonging to this update
) => {
// eslint-disable-next-line no-console
console.info({
id,
phase,
actualDuration,
baseDuration,
startTime,
commitTime,
interactions,
});
};
Loading

0 comments on commit d565045

Please sign in to comment.