@richiemccoll
Frontend Engineer
London 🇬🇧
@richiemccoll
@richiemccoll
@richiemccoll
@richiemccoll
Source: Cloudflare - Getting Faster Performance whitepaper
@richiemccoll
To me, speedy software is the difference between an application smoothly integrating into your life, and one called upon with great reluctance."
@richiemccoll
@richiemccoll
The Measure, Analyse and Fix cycle
@richiemccoll
git clone https://github.com/richiemccoll/visualising-front-end-performance-demo.git
git checkout before-fixes
npm i
npm start@richiemccoll
https://aerotwist.com/blog/the-anatomy-of-a-frame/
@richiemccoll
@richiemccoll
How do we measure?
@richiemccoll
User Timings API
function createMark() {
window.performance.mark('createMark-🎉-start');
// ...
window.performance.mark('createMark-🎉-end');
}
@richiemccoll
function createMarkAndMeasure() {
window.performance.mark('createMark-🎉-start');
// ...
window.performance.mark('createMark-🎉-end');
window.performance.measure(
'createMark-🎂-measure',
'createMark-🎉-start',
'createMark-🎉-end'
);
}
@richiemccoll
User Timings API
Mark the start
usePrevious hook
Mark the end
Create the measure
@richiemccoll
<button
onClick={() => {
window.performance.mark("changingOrder-start");
setOrder();
}}
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Click to view {order} launches
</button>Measuring and Analysing
@richiemccoll
Store the value from the previous render in a ref.
Measuring and Analysing
function usePrevious(value) {
const ref = useRef();
useEffect(() => {
ref.current = value;
});
return ref.current;
}@richiemccoll
Measuring and Analysing
function LatestLaunchList({ launches, setOrder, order = "older" }) {
const prevOrder = usePrevious(order);
useEffect(() => {
if (prevOrder && prevOrder !== order) {
performance.mark("changingOrder-end");
performance.measure(
"changingOrder-measure",
"changingOrder-start",
"changingOrder-end"
);
}
}, [order, prevOrder]);
// ...
}@richiemccoll
What is the baseline?
@richiemccoll
“List Virtualisation” or “windowing”.
image: https://web.dev/virtualize-long-lists-react-window/
@richiemccoll
@richiemccoll
@richiemccoll
@richiemccoll
(and more)
@richiemccoll
Scripting: 6849ms
Scripting: 4554ms
Style: 1475ms
Style: 836ms
Paint: 506ms
Paint: 205ms
@richiemccoll
(-34%)
(-43%)
(-59%)
Chrome Remote Debug Profile on FireTV with playback
January 2020
https://github.com/jaredLunde/masonic
import { Masonry } from 'masonic';
<div className="flex flex-wrap -m-4">
<Masonry
items={launches}
columnWidth={300}
render={({ data: launch }) => {
return (
<Card
name={launch.name}
details={launch.details}
image={launch.imgUrl}
url={launch.url}
date={launch.date}
/>
);
}}
/>
</div>"A performant and versatile virtualized masonry grid for React"
@richiemccoll
What is the new baseline?
@richiemccoll
@richiemccoll
@richiemccoll