Skip to content

Commit

Permalink
added Profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova committed Oct 7, 2020
1 parent 4dff549 commit 02fc972
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 18 deletions.
7 changes: 4 additions & 3 deletions test/perf/tests/box-emotion/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@

import React from 'react';
import React, { Profiler } 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 BoxEmotion = styledEmotion('div')(styleFunction);

const App = () => {
return (
<>
<Profiler id="box-emotion" onRender={logReactMetrics}>
{new Array(100).fill().map(() => (
<EmotionTheme theme={materialSystemTheme}>
<BoxEmotion
Expand All @@ -24,7 +25,7 @@ const App = () => {
</BoxEmotion>
</EmotionTheme>
))}
</>
</Profiler>
);
}

Expand Down
7 changes: 4 additions & 3 deletions test/perf/tests/box-material-ui-styles/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@

import React from 'react';
import React, { Profiler } 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();

const App = () => {
return (
<>
<Profiler id="box-material-ui-system" onRender={logReactMetrics}>
{new Array(100).fill().map(() => (
<StylesThemeProvider theme={materialSystemTheme}>
<BoxStyles
Expand All @@ -23,7 +24,7 @@ const App = () => {
</BoxStyles>
</StylesThemeProvider>
))}
</>
</Profiler>
);
}

Expand Down
7 changes: 4 additions & 3 deletions test/perf/tests/box-styled-components/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from 'react';
import React, { Profiler } 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);

const App = () => {
return (
<>
<Profiler id="box-styled-components" onRender={logReactMetrics}>
{new Array(100).fill().map(() => (
<StyledComponentsThemeProvider theme={materialSystemTheme}>
<BoxStyleComponents
Expand All @@ -25,7 +26,7 @@ const App = () => {
</BoxStyleComponents>
</StyledComponentsThemeProvider>
))}
</>
</Profiler>
);
}

Expand Down
7 changes: 4 additions & 3 deletions test/perf/tests/naked-styled-components/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from 'react';
import React, { Profiler } 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);

const App = () => {
return (
<>
<Profiler id="naked-styled-components" onRender={logReactMetrics}>
{new Array(100).fill().map(() => (
<StyledComponentsThemeProvider theme={materialSystemTheme}>
<NakedStyleComponents
Expand All @@ -25,7 +26,7 @@ const App = () => {
</NakedStyleComponents>
</StyledComponentsThemeProvider>
))}
</>
</Profiler>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React from 'react';
import React, { Profiler } 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);

const App = () => {
return (
<>
<Profiler id="styled-components-box-material-ui-system" onRender={logReactMetrics}>
{new Array(100).fill().map(() => (
<StyledComponentsThemeProvider theme={materialSystemTheme}>
<BoxMaterialSystem
Expand All @@ -25,7 +26,7 @@ const App = () => {
</BoxMaterialSystem>
</StyledComponentsThemeProvider>
))}
</>
</Profiler>
);
}

Expand Down
7 changes: 4 additions & 3 deletions test/perf/tests/styled-components-box-styled-system/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import React, { Profiler } 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);
Expand All @@ -16,7 +17,7 @@ styledSystemTheme.fonts = styledSystemTheme.typography;

const App = () => {
return (
<>
<Profiler id="styled-components-box-styled-system" onRender={logReactMetrics}>
{new Array(100).fill().map(() => (
<StyledComponentsThemeProvider theme={styledSystemTheme}>
<BoxStyledSystem
Expand All @@ -30,7 +31,7 @@ const App = () => {
</BoxStyledSystem>
</StyledComponentsThemeProvider>
))}
</>
</Profiler>
);
}

Expand Down
19 changes: 19 additions & 0 deletions test/perf/tests/utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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
) => {
console.info({
id,
phase,
actualDuration,
baseDuration,
startTime,
commitTime,
interactions,
});
}
8 changes: 8 additions & 0 deletions test/perf/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@ module.exports = {
},
]),
},
resolve: {
...webpackBaseConfig.resolve,
alias: {
...webpackBaseConfig.resolve.alias,
'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling',
}
}
};

0 comments on commit 02fc972

Please sign in to comment.