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

[system] Add browser benchmark #22923

Merged
merged 51 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c2d31cc
add emotion peer dependencies
mnajdova Sep 25, 2020
5ae933f
fixed types & tests
mnajdova Sep 25, 2020
18b0668
prettier
mnajdova Sep 25, 2020
f0ef95c
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 28, 2020
c7bebb8
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 28, 2020
92b2d6e
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 28, 2020
13da531
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 29, 2020
cf5d9a5
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 29, 2020
b8d1291
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Sep 30, 2020
a9d8690
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Oct 2, 2020
497830a
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Oct 5, 2020
d50ea1e
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Oct 5, 2020
0f6a4cd
Merge branch 'next' of https://github.com/mui-org/material-ui into next
mnajdova Oct 7, 2020
616bd28
wip
mnajdova Oct 7, 2020
bcd581e
spaces
mnajdova Oct 7, 2020
0fde5b1
Added all system tests
mnajdova Oct 7, 2020
73105d0
moved wait-on and concurrently to devDependencies
mnajdova Oct 7, 2020
520cbc5
fixed & improvements
mnajdova Oct 7, 2020
b779a2a
moved serve + wait in perf
mnajdova Oct 7, 2020
13c3f6e
improved perf metrics
mnajdova Oct 7, 2020
4dff549
improved emotion example
mnajdova Oct 7, 2020
02fc972
added Profiler
mnajdova Oct 7, 2020
3ff75fd
Update test/perf/webpack.config.js
mnajdova Oct 7, 2020
95cad05
Olivier's feedback
mnajdova Oct 7, 2020
781c969
Merge branch 'feat/perf-browser-tests' of https://github.com/mnajdova…
mnajdova Oct 7, 2020
75425db
deduplicate
mnajdova Oct 7, 2020
37f61a9
removed fuu, prettier
mnajdova Oct 7, 2020
6abea87
lint
mnajdova Oct 7, 2020
e43ff18
lint errors
mnajdova Oct 8, 2020
500cfa2
renamed perf + tests to benchmark
mnajdova Oct 8, 2020
7127ed9
disable prefer default export from utils
mnajdova Oct 8, 2020
03a10e8
Fix mode confusion
eps1lon Oct 8, 2020
1446315
Exit script when it's done
eps1lon Oct 8, 2020
acda962
Remove unnecessary wrappers
eps1lon Oct 8, 2020
28f1ab0
Merge pull request #9 from eps1lon/feat/perf-browser-tests-review1
mnajdova Oct 8, 2020
b4c0e13
Olivier's comments
mnajdova Oct 11, 2020
32f1219
lint, added 1000 components per scenario
mnajdova Oct 11, 2020
f0c65a5
lint
mnajdova Oct 11, 2020
9763fbd
have sub millisecond measurments
oliviertassinari Oct 11, 2020
05e55ec
added noop and README
mnajdova Oct 11, 2020
60aa699
prettier
mnajdova Oct 12, 2020
0a835ef
Update benchmark/scripts/benchmark.js
mnajdova Oct 12, 2020
da8bf24
Merge pull request #10 from oliviertassinari/sub-ms
mnajdova Oct 12, 2020
73b06eb
Merge branch 'next' into feat/perf-browser-tests
mnajdova Oct 12, 2020
6a94b91
formatted median print
mnajdova Oct 12, 2020
91dcbfe
reverted dependencies
mnajdova Oct 12, 2020
ff5e451
Merge branch 'next' into feat/perf-browser-tests
mnajdova Oct 12, 2020
da39d72
conflicts
mnajdova Oct 12, 2020
4ed84c8
dependencies removed
mnajdova Oct 12, 2020
5292dba
Merge branch 'next' into feat/perf-browser-tests
mnajdova Oct 12, 2020
2df44b7
conflicts
mnajdova Oct 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
13 changes: 13 additions & 0 deletions benchmark/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';

// 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;

ReactDOM.render(<Component />, 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>
);
}
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,
});
};