Slide 1

Slide 1 text

Breaking down long tasks

Slide 2

Slide 2 text

Poor responsiveness/jankiness

Slide 3

Slide 3 text

INP • Why replace FID?

Slide 4

Slide 4 text

https://almanac.httparchive.org/en/2022/performance#fig-41

Slide 5

Slide 5 text

gives you the worst interaction value, doesn’t tell you whats that worst interaction!

Slide 6

Slide 6 text

Find the slow interactions - field data - lab data

Slide 7

Slide 7 text

Field data • Pagespeed using CruX • Your RUM Provider • Web vitals JS library

Slide 8

Slide 8 text

What to record? • INP value • Responsible element selector • Loading state at the point • Interaction start time • Event type (tap, click, keyboard event)

Slide 9

Slide 9 text

https://app.datadoghq.eu/rum/performance-monitoring

Slide 10

Slide 10 text

Not great INP value! RUM provider showed the bad INP value, but not the interaction causing it.

Slide 11

Slide 11 text

Record using web vitals JS library (the attribution build)

Slide 12

Slide 12 text

import { onINP } from 'web-vitals/attribution';

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Report the metrics collected to your analytics tool

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Have the field data, yayy! 🎉 But, how to reproduce and fix?

Slide 19

Slide 19 text

…comes testing in the lab

Slide 20

Slide 20 text

Web vitals chrome extension

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Cannot use extensions? Mobile device? let worstInp = 0; const observer = new PerformanceObserver((list, obs, options) => { for (let entry of list.getEntries()) { if (!entry.interactionId) continue; entry.renderTime = entry.startTime + entry.duration; worstInp = Math.max(entry.duration, worstInp); console.log('[Interaction]', entry.duration, `type: ${entry.name} interactionCount: ${performance.interactionCount}, worstInp: ${worstInp}`, entry, options); } }); observer.observe({ type: 'event', durationThreshold: 0, // 16 minimum by spec buffered: true });

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Still no luck? Performance profile, here I come!

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

- Input delays? - Expensive event callbacks?

Slide 28

Slide 28 text

scheduler.yield() https://developer.chrome.com/origintrials/#/view_trial/836543630784069633

Slide 29

Slide 29 text

startTransition() API

Slide 30

Slide 30 text

rendering the updates can be the most challenging! (a.k.a presentation delay)

Slide 31

Slide 31 text

Large DOM sizes Leads to Style recalculation

Slide 32

Slide 32 text

Forced reflows – CSS selector complexity .box:nth-last-child(-n+1) .title { /* styles */ } https://web.dev/articles/reduce-the-scope-and-complexity-of-style-calculations

Slide 33

Slide 33 text

Long tasks API • Tells you a long task happened and took this long, but doesn't tell what might have caused it. – Basic attribution model • Doesn't count the rendering updates time, happens in a different task.

Slide 34

Slide 34 text

Long Animation frames observer.observe({ type: 'long-animation-frame', buffered: true });

Slide 35

Slide 35 text

• Name • Event type • Timing data • Window attribution etc. Better attribution https://developer.chrome.com/articles/long-animation-frames/

Slide 36

Slide 36 text

chrome://flags/#enable-experimental-web-platform-features

Slide 37

Slide 37 text

Origin trials for LoAF https://developer.chrome.com/origintrials/#/view_trial/3935020174414970881

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Strategies to yield to the main thread

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Deferred events pushed to the end of the queue?

Slide 42

Slide 42 text

scheduler .yield() developer.chrome.com/origintrials

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Scheduler .postTask()

Slide 45

Slide 45 text

scheduler .postTask(method, {priority: ‘user-blocking’ }) scheduler .postTask(method, {priority: ‘user-visible’ }) scheduler .postTask(method, {priority: ‘background’ })

Slide 46

Slide 46 text

navigator.scheduling.isInputPending()

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Quick recap: • INP – pending CWV for March 2024 • Gives good attribution data to diagnose • Leads you to measure field data using web vitals JS library for example • We should then use lab tools to reproduce the slowness • Understanding delays in the browser • Strategies to fix the main thread blocking.

Slide 49

Slide 49 text

thank you! x.com/TheNishuGoel