Skip to content

Commit 02fc972

Browse files
committed
added Profiler
1 parent 4dff549 commit 02fc972

File tree

8 files changed

+51
-18
lines changed

8 files changed

+51
-18
lines changed

test/perf/tests/box-emotion/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11

2-
import React from 'react';
2+
import React, { Profiler } from 'react';
33
import { createMuiTheme } from '@material-ui/core/styles';
44
import styledEmotion from '@emotion/styled';
55
import { ThemeProvider as EmotionTheme } from 'emotion-theming';
66
import { styleFunction } from '@material-ui/core/Box';
7+
import { logReactMetrics } from '../utils';
78

89
const materialSystemTheme = createMuiTheme();
910
const BoxEmotion = styledEmotion('div')(styleFunction);
1011

1112
const App = () => {
1213
return (
13-
<>
14+
<Profiler id="box-emotion" onRender={logReactMetrics}>
1415
{new Array(100).fill().map(() => (
1516
<EmotionTheme theme={materialSystemTheme}>
1617
<BoxEmotion
@@ -24,7 +25,7 @@ const App = () => {
2425
</BoxEmotion>
2526
</EmotionTheme>
2627
))}
27-
</>
28+
</Profiler>
2829
);
2930
}
3031

test/perf/tests/box-material-ui-styles/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11

2-
import React from 'react';
2+
import React, { Profiler } from 'react';
33
import { createMuiTheme } from '@material-ui/core/styles';
44
import { ThemeProvider as StylesThemeProvider } from '@material-ui/styles';
55
import BoxStyles from '@material-ui/core/Box';
6+
import { logReactMetrics } from '../utils';
67

78
const materialSystemTheme = createMuiTheme();
89

910
const App = () => {
1011
return (
11-
<>
12+
<Profiler id="box-material-ui-system" onRender={logReactMetrics}>
1213
{new Array(100).fill().map(() => (
1314
<StylesThemeProvider theme={materialSystemTheme}>
1415
<BoxStyles
@@ -23,7 +24,7 @@ const App = () => {
2324
</BoxStyles>
2425
</StylesThemeProvider>
2526
))}
26-
</>
27+
</Profiler>
2728
);
2829
}
2930

test/perf/tests/box-styled-components/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import React from 'react';
1+
import React, { Profiler } from 'react';
22
import { createMuiTheme } from '@material-ui/core/styles';
33
import { styleFunction } from '@material-ui/core/Box';
44
import styledComponents, {
55
ThemeProvider as StyledComponentsThemeProvider,
66
} from 'styled-components';
7+
import { logReactMetrics } from '../utils';
78

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

1112
const App = () => {
1213
return (
13-
<>
14+
<Profiler id="box-styled-components" onRender={logReactMetrics}>
1415
{new Array(100).fill().map(() => (
1516
<StyledComponentsThemeProvider theme={materialSystemTheme}>
1617
<BoxStyleComponents
@@ -25,7 +26,7 @@ const App = () => {
2526
</BoxStyleComponents>
2627
</StyledComponentsThemeProvider>
2728
))}
28-
</>
29+
</Profiler>
2930
);
3031
}
3132

test/perf/tests/naked-styled-components/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import React from 'react';
1+
import React, { Profiler } from 'react';
22
import { createMuiTheme } from '@material-ui/core/styles';
33
import { spacing } from '@material-ui/system';
44
import styledComponents, {
55
ThemeProvider as StyledComponentsThemeProvider,
66
} from 'styled-components';
7+
import { logReactMetrics } from '../utils';
78

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

1112
const App = () => {
1213
return (
13-
<>
14+
<Profiler id="naked-styled-components" onRender={logReactMetrics}>
1415
{new Array(100).fill().map(() => (
1516
<StyledComponentsThemeProvider theme={materialSystemTheme}>
1617
<NakedStyleComponents
@@ -25,7 +26,7 @@ const App = () => {
2526
</NakedStyleComponents>
2627
</StyledComponentsThemeProvider>
2728
))}
28-
</>
29+
</Profiler>
2930
);
3031
}
3132

test/perf/tests/styled-components-box-material-ui-system/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import React from 'react';
1+
import React, { Profiler } from 'react';
22
import { createMuiTheme } from '@material-ui/core/styles';
33
import styledComponents, {
44
ThemeProvider as StyledComponentsThemeProvider,
55
} from 'styled-components';
66
import { spacing, palette, typography, compose } from '@material-ui/system';
7+
import { logReactMetrics } from '../utils';
78

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

1213
const App = () => {
1314
return (
14-
<>
15+
<Profiler id="styled-components-box-material-ui-system" onRender={logReactMetrics}>
1516
{new Array(100).fill().map(() => (
1617
<StyledComponentsThemeProvider theme={materialSystemTheme}>
1718
<BoxMaterialSystem
@@ -25,7 +26,7 @@ const App = () => {
2526
</BoxMaterialSystem>
2627
</StyledComponentsThemeProvider>
2728
))}
28-
</>
29+
</Profiler>
2930
);
3031
}
3132

test/perf/tests/styled-components-box-styled-system/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import React from 'react';
1+
import React, { Profiler } from 'react';
22
import { createMuiTheme } from '@material-ui/core/styles';
33
import styledComponents, {
44
ThemeProvider as StyledComponentsThemeProvider,
55
} from 'styled-components';
66
import { space, color, fontFamily, fontSize, compose } from 'styled-system';
7+
import { logReactMetrics } from '../utils';
78

89
const styledSystem = compose(color, space, fontFamily, fontSize);
910
const BoxStyledSystem = styledComponents('div')(styledSystem);
@@ -16,7 +17,7 @@ styledSystemTheme.fonts = styledSystemTheme.typography;
1617

1718
const App = () => {
1819
return (
19-
<>
20+
<Profiler id="styled-components-box-styled-system" onRender={logReactMetrics}>
2021
{new Array(100).fill().map(() => (
2122
<StyledComponentsThemeProvider theme={styledSystemTheme}>
2223
<BoxStyledSystem
@@ -30,7 +31,7 @@ const App = () => {
3031
</BoxStyledSystem>
3132
</StyledComponentsThemeProvider>
3233
))}
33-
</>
34+
</Profiler>
3435
);
3536
}
3637

test/perf/tests/utils/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export const logReactMetrics = (
2+
id, // the "id" prop of the Profiler tree that has just committed
3+
phase, // either "mount" (if the tree just mounted) or "update" (if it re-rendered)
4+
actualDuration, // time spent rendering the committed update
5+
baseDuration, // estimated time to render the entire subtree without memoization
6+
startTime, // when React began rendering this update
7+
commitTime, // when React committed this update
8+
interactions // the Set of interactions belonging to this update
9+
) => {
10+
console.info({
11+
id,
12+
phase,
13+
actualDuration,
14+
baseDuration,
15+
startTime,
16+
commitTime,
17+
interactions,
18+
});
19+
}

test/perf/webpack.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ module.exports = {
2121
},
2222
]),
2323
},
24+
resolve: {
25+
...webpackBaseConfig.resolve,
26+
alias: {
27+
...webpackBaseConfig.resolve.alias,
28+
'react-dom$': 'react-dom/profiling',
29+
'scheduler/tracing': 'scheduler/tracing-profiling',
30+
}
31+
}
2432
};

0 commit comments

Comments
 (0)