GoogleChrome / GoogleChrome/lighthouse

Lighthouse "Script Parse" metric is off

Open
#8,094 3 comments 0 reactions 0 assignees View on GitHub
P2
Dominant language
JavaScript
Stars
30.8k
Forks
9.8k
Avg merge
1d 20h
Merged PRs (30d)
19

Description

Parse metrics show up in Lighthouse through the "Reduce JavaScript execution time" diagnostic in the Performance audit. The code is in `bootup-time.js` (https://github.com/GoogleChrome/lighthouse/blob/b8ee28f2f4c6eb5bf02065e731e612f8f46b4e7f/lighthouse-core/audits/bootup-time.js#L134-L139) and looks for the `scriptParseCompile` task group, which Lighthouse [defines](https://github.com/GoogleChrome/lighthouse/blob/54baf91bf7832153347d8e4daf9e05da86d5d5dd/lighthouse-core/lib/task-groups.js#L55-L59) based on the following trace events:

```
scriptParseCompile: {
id: 'scriptParseCompile',
label: 'Script Parsing & Compilation',
traceEventNames: ['v8.compile', 'v8.compileModule', 'v8.parseOnBackground'],
},
```

An example report looks as follows:

![](https://user-images.githubusercontent.com/81942/55781760-2d741300-5aab-11e9-9476-c5001f702bfb.jpg)

"Script Parse" intends to cover "Script Parse + Compile" and should probably be renamed as such, but even then the metrics are misattributed. Lighthouse is currently underreporting "[main thread] script parse + compile" and overreporting "script evaluation" by roughly the same amount, due to “lazy” compilations (i.e. on-demand compilation of non-IIFEs) and eval compilations falling into the “evaluation” rather than “parse & compile” bucket. The exposed metric includes the `v8.parseOnBackground` trace event, although time spent on background threads explicitly does not contribute to main thread blocking time and is therefore not useful to report --- in fact, reporting it can be harmful. The current Lighthouse-reported metrics might steer developers away from code splitting & serving multiple smaller scripts (which is great for parallelization, since we then spawn multiple small tasks) as opposed to a single massive script file.

Suggested changes in Lighthouse:

1. rename "Script Parse" to "Script Parse + Compile" if that's indeed what we intend to show
2. only count main thread time spent parsing + compiling, since that's what matters

cc @addyosmani @verwaest @LeszekSwirski

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.