Skip to content

Commit

Permalink
diagnostics: Re-add timer for store hydration.
Browse files Browse the repository at this point in the history
The store hydration timer got removed in bf659a2 when we upgraded
from redux-persist v4 to v5 due to structural differences in the redux
initialization. Re-add a timer. Do this with a new, reusable Timer
component that logs the duration of its existence to timing.js. This
works for roughly measuring the redux-persist execution time, because
that's all the app is doing while the loading screen is shown. No
other big actions distort this measurement, because no significant
actions are dispatched as long as the state is not properly loaded.
  • Loading branch information
roberthoenig committed Aug 1, 2018
1 parent a954500 commit e7610ca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/boot/StoreProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PersistGate } from 'redux-persist/lib/integration/react';
import type { ChildrenArray } from '../types';
import store, { persistor } from './store';
import LoadingScreen from '../start/LoadingScreen';
import RenderTimer from '../diagnostics/RenderTimer';

type Props = {
children: ChildrenArray<*>,
Expand All @@ -17,7 +18,14 @@ export default class StoreHydrator extends PureComponent<Props> {
render() {
return (
<Provider store={store}>
<PersistGate loading={<LoadingScreen />} persistor={persistor}>
<PersistGate
loading={
<RenderTimer name="Store hydration">
<LoadingScreen />
</RenderTimer>
}
persistor={persistor}
>
{this.props.children}
</PersistGate>
</Provider>
Expand Down
24 changes: 24 additions & 0 deletions src/diagnostics/RenderTimer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* @flow */
import { PureComponent } from 'react';

import type { ChildrenArray } from '../types';
import timing from '../utils/timing';

type Props = {
children: ChildrenArray<*>,
name: string,
};

export default class RenderTimer extends PureComponent<Props> {
componentDidMount() {
timing.start(this.props.name);
}

componentWillUnmount() {
timing.end(this.props.name);
}

render() {
return this.props.children;
}
}

0 comments on commit e7610ca

Please sign in to comment.