GoogleChrome / GoogleChrome/lighthouse
Audit: Costly image decodes
- Dominant language
- JavaScript
- Stars
- 30.8k
- Forks
- 9.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 19
Description
https://stats.yarnpkg.com/ loads quick but has surprisingly high "Composite Layers" cost. But as it turns out, it's just stalled in Composite Layers as it waits for an "Image Decode" in the raster threads to finish:

The root issue here is that the image is shipped as 5000px wide, but only shown as 400px wide. Whoops. :) We already flag oversize images and calculate the download overhead cost:

However, we are ignoring the runtime costs (decode and resize). And in this case, we can see it's significant.
### Implementation
Processing the raw trace for this is surprisingly hard as the image URL isn't in the `DecodeImage` trace event, but linked via two other references (`LazyPixelRef` lol). Caseq points out this particular area is one of the most complicated to put together... So given that, it makes more sense to let `devtools-timeline-model` do our heavy lifting..
The basic flow:
```js
for (const thread of someTimelineModel._virtualThreads) {
for (const event of thread.events) {
if (event.name === 'Decode Image') {
data = TimelineModel.TimelineData.forEvent(event);
if (event.duration > 10)
console.log({url: data.url, duration: event.duration, event, data});
}
}
}
```
TBD on how we surface this cost to the user, since we'd now have calculated both network and runtime cost of this issue.
Contributor guide
Assessment
This issue has not been assessed yet.