This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
unstable_trace as trace, | |
} from 'scheduler/tracing' | |
<input | |
type="text" | |
value={name} | |
onChange={e => { | |
trace('Enter user name', performance.now(), () => | |
onChange(e.target.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ROUNDS = 100_000 | |
const Benchmark = () => { | |
const [took, setTook] = useState() | |
const [round, setRound] = useState(1) | |
const start = useRef(performance.now()) | |
useEffect(() => { | |
if (round < ROUNDS) { | |
setRound(round + 1) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using Yarn | |
yarn build --profile | |
# Using NPM | |
npm run build -- --profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
//... | |
resolve: { | |
alias: { | |
'react-dom$': 'react-dom/profiling', | |
'scheduler/tracing': 'scheduler/tracing-profiling', | |
} | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Profiler | |
id="user-profile" | |
onRender={( | |
id, | |
phase, | |
actualTime, | |
baseTime, | |
startTime, | |
commitTime, | |
interactions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from 'react' | |
const SlowComponent = ({ noSlowdown }) => { | |
const arr = [] | |
if (!noSlowdown) { | |
for (var i = 1000000 - 1; i >= 0; i--) { | |
arr.push(i) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const NotificationItem = React.memo<Props>( | |
({ notification, onMmarkAsRead, session }) => <div>...</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const NotificationItem = ({ notification, onMmarkAsRead, session }: Props) => <div>...</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const App = () => { | |
const loadData = id => ({ id, value: 'some' }) | |
const [_, setDummy] = useState() | |
return ( | |
<div className="App"> | |
<button onClick={() => setDummy(Date.now())} /> | |
<SlowComponent | |
onClick={React.useCallback(() => loadData('dummy'), [])} | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const App = () => { | |
const loadData = id => ({ id, value: 'some' }) | |
const [_, setDummy] = useState() | |
return ( | |
<div className="App"> | |
<button onClick={() => setDummy(Date.now())}>Render</button> | |
<SlowComponent onClick={() => loadData('dummy')} /> | |
</div> | |
) |