Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(legacy-javascript): use source maps #10564

Merged
merged 12 commits into from
Apr 27, 2020
Merged

core(legacy-javascript): use source maps #10564

merged 12 commits into from
Apr 27, 2020

Conversation

connorjclark
Copy link
Collaborator

@connorjclark connorjclark commented Apr 9, 2020

Part of #10369

If source maps are present, use our knowledge of what node module a polyfill comes from to find signals. Pattern matching takes precedence - the line/column information is more accurate. Otherwise, the first mapping entry for the relevant module is used as the source location.

Because the case of no source maps is important by itself, I introduced a second summary json file in the test.

Diff between the two new summary jsons (This represents the improvement in using maps + pattern matching) (same as what github shows for summary-signals.json in this PR, but this markdown is a bit nicer to look at) :

diff --git a/summary-signals-nomaps.json b/summary-signals.json
index 690bd7b27..022109f5e 100644
--- a/summary-signals-nomaps.json
+++ b/summary-signals.json
@@ -1,51 +1,13 @@
 {
-  "totalSignals": 203,
+  "totalSignals": 251,
   "variantsMissingSignals": [
-    "core-js-2-only-polyfill/es6-array-filter",
-    "core-js-2-only-polyfill/es6-array-map",
-    "core-js-2-only-polyfill/es6-array-reduce",
-    "core-js-2-only-polyfill/es6-array-reduce-right",
-    "core-js-2-only-polyfill/es6-array-some",
-    "core-js-2-only-polyfill/es6-date-to-string",
-    "core-js-2-only-polyfill/es6-function-name",
-    "core-js-2-only-polyfill/es6-object-freeze",
-    "core-js-2-only-polyfill/es6-object-get-own-property-descriptor",
-    "core-js-2-only-polyfill/es6-object-get-own-property-names",
-    "core-js-2-only-polyfill/es6-object-get-prototype-of",
-    "core-js-2-only-polyfill/es6-object-is-extensible",
-    "core-js-2-only-polyfill/es6-object-is-frozen",
-    "core-js-2-only-polyfill/es6-object-is-sealed",
-    "core-js-2-only-polyfill/es6-object-keys",
-    "core-js-2-only-polyfill/es6-object-prevent-extensions",
-    "core-js-2-only-polyfill/es6-object-seal",
-    "core-js-2-only-polyfill/es6-reflect-define-property",
-    "core-js-2-only-polyfill/es6-string-trim",
     "core-js-2-preset-env-esmodules/true",
-    "core-js-3-only-polyfill/es6-array-filter",
-    "core-js-3-only-polyfill/es6-array-map",
-    "core-js-3-only-polyfill/es6-array-reduce",
-    "core-js-3-only-polyfill/es6-array-reduce-right",
-    "core-js-3-only-polyfill/es6-array-some",
-    "core-js-3-only-polyfill/es6-date-to-string",
-    "core-js-3-only-polyfill/es6-function-name",
-    "core-js-3-only-polyfill/es6-object-freeze",
-    "core-js-3-only-polyfill/es6-object-get-own-property-descriptor",
-    "core-js-3-only-polyfill/es6-object-get-own-property-names",
-    "core-js-3-only-polyfill/es6-object-get-prototype-of",
-    "core-js-3-only-polyfill/es6-object-is-extensible",
-    "core-js-3-only-polyfill/es6-object-is-frozen",
-    "core-js-3-only-polyfill/es6-object-is-sealed",
-    "core-js-3-only-polyfill/es6-object-keys",
-    "core-js-3-only-polyfill/es6-object-prevent-extensions",
-    "core-js-3-only-polyfill/es6-object-seal",
-    "core-js-3-only-polyfill/es6-reflect-define-property",
-    "core-js-3-only-polyfill/es6-string-trim",
     "core-js-3-preset-env-esmodules/true"
   ],
   "variants": [
     {
       "name": "core-js-2-only-polyfill/es6-array-filter",
-      "signals": ""
+      "signals": "Array.prototype.filter"
     },
     {
       "name": "core-js-2-only-polyfill/es6-array-find",
@@ -53,7 +15,7 @@
     },
     {
       "name": "core-js-2-only-polyfill/es6-array-find-index",
-      "signals": "Array.prototype.findIndex"
+      "signals": "Array.prototype.findIndex, Array.prototype.find"
     },
     {
       "name": "core-js-2-only-polyfill/es6-array-for-each",
@@ -73,7 +35,7 @@
     },
     {
       "name": "core-js-2-only-polyfill/es6-array-map",
-      "signals": ""
+      "signals": "Array.prototype.map"
     },
     {
       "name": "core-js-2-only-polyfill/es6-array-of",
@@ -81,15 +43,15 @@
     },
     {
       "name": "core-js-2-only-polyfill/es6-array-reduce",
-      "signals": ""
+      "signals": "Array.prototype.reduce"
     },
     {
       "name": "core-js-2-only-polyfill/es6-array-reduce-right",
-      "signals": ""
+      "signals": "Array.prototype.reduce, Array.prototype.reduceRight"
     },
     {
       "name": "core-js-2-only-polyfill/es6-array-some",
-      "signals": ""
+      "signals": "Array.prototype.some"
     },
     {
       "name": "core-js-2-only-polyfill/es6-date-now",
@@ -105,11 +67,11 @@
     },
     {
       "name": "core-js-2-only-polyfill/es6-date-to-string",
-      "signals": ""
+      "signals": "Date.prototype.toString"
     },
     {
       "name": "core-js-2-only-polyfill/es6-function-name",
-      "signals": ""
+      "signals": "Function.prototype.name"
     },
     {
       "name": "core-js-2-only-polyfill/es6-map",
@@ -149,43 +111,43 @@
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-freeze",
-      "signals": ""
+      "signals": "Object.freeze"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-get-own-property-descriptor",
-      "signals": ""
+      "signals": "Object.getOwnPropertyDescriptor"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-get-own-property-names",
-      "signals": ""
+      "signals": "Object.getOwnPropertyNames"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-get-prototype-of",
-      "signals": ""
+      "signals": "Object.getPrototypeOf"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-is-extensible",
-      "signals": ""
+      "signals": "Object.isExtensible"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-is-frozen",
-      "signals": ""
+      "signals": "Object.isFrozen"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-is-sealed",
-      "signals": ""
+      "signals": "Object.isSealed"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-keys",
-      "signals": ""
+      "signals": "Object.keys"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-prevent-extensions",
-      "signals": ""
+      "signals": "Object.preventExtensions"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-seal",
-      "signals": ""
+      "signals": "Object.seal"
     },
     {
       "name": "core-js-2-only-polyfill/es6-object-set-prototype-of",
@@ -205,7 +167,7 @@
     },
     {
       "name": "core-js-2-only-polyfill/es6-reflect-define-property",
-      "signals": ""
+      "signals": "Reflect.defineProperty"
     },
     {
       "name": "core-js-2-only-polyfill/es6-reflect-delete-property",
@@ -217,11 +179,11 @@
     },
     {
       "name": "core-js-2-only-polyfill/es6-reflect-get-own-property-descriptor",
-      "signals": "Reflect.getOwnPropertyDescriptor"
+      "signals": "Reflect.getOwnPropertyDescriptor, Reflect.get"
     },
     {
       "name": "core-js-2-only-polyfill/es6-reflect-get-prototype-of",
-      "signals": "Reflect.getPrototypeOf"
+      "signals": "Reflect.getPrototypeOf, Reflect.get"
     },
     {
       "name": "core-js-2-only-polyfill/es6-reflect-has",
@@ -245,7 +207,7 @@
     },
     {
       "name": "core-js-2-only-polyfill/es6-reflect-set-prototype-of",
-      "signals": "Reflect.setPrototypeOf"
+      "signals": "Reflect.setPrototypeOf, Reflect.set"
     },
     {
       "name": "core-js-2-only-polyfill/es6-set",
@@ -281,7 +243,7 @@
     },
     {
       "name": "core-js-2-only-polyfill/es6-string-trim",
-      "signals": ""
+      "signals": "String.prototype.trim"
     },
     {
       "name": "core-js-2-only-polyfill/es6-typed-array-buffer",
@@ -369,7 +331,7 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-array-filter",
-      "signals": ""
+      "signals": "Array.prototype.filter"
     },
     {
       "name": "core-js-3-only-polyfill/es6-array-find",
@@ -377,7 +339,7 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-array-find-index",
-      "signals": "Array.prototype.findIndex"
+      "signals": "Array.prototype.findIndex, Array.prototype.find"
     },
     {
       "name": "core-js-3-only-polyfill/es6-array-for-each",
@@ -397,7 +359,7 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-array-map",
-      "signals": ""
+      "signals": "Array.prototype.map"
     },
     {
       "name": "core-js-3-only-polyfill/es6-array-of",
@@ -405,15 +367,15 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-array-reduce",
-      "signals": ""
+      "signals": "Array.prototype.reduce"
     },
     {
       "name": "core-js-3-only-polyfill/es6-array-reduce-right",
-      "signals": ""
+      "signals": "Array.prototype.reduce, Array.prototype.reduceRight"
     },
     {
       "name": "core-js-3-only-polyfill/es6-array-some",
-      "signals": ""
+      "signals": "Array.prototype.some"
     },
     {
       "name": "core-js-3-only-polyfill/es6-date-now",
@@ -429,11 +391,11 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-date-to-string",
-      "signals": ""
+      "signals": "Date.prototype.toString"
     },
     {
       "name": "core-js-3-only-polyfill/es6-function-name",
-      "signals": ""
+      "signals": "Function.prototype.name"
     },
     {
       "name": "core-js-3-only-polyfill/es6-map",
@@ -473,43 +435,43 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-freeze",
-      "signals": ""
+      "signals": "Object.freeze"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-get-own-property-descriptor",
-      "signals": ""
+      "signals": "Object.getOwnPropertyDescriptor"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-get-own-property-names",
-      "signals": ""
+      "signals": "Object.getOwnPropertyNames"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-get-prototype-of",
-      "signals": ""
+      "signals": "Object.getPrototypeOf"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-is-extensible",
-      "signals": ""
+      "signals": "Object.isExtensible"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-is-frozen",
-      "signals": ""
+      "signals": "Object.isFrozen"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-is-sealed",
-      "signals": ""
+      "signals": "Object.isSealed"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-keys",
-      "signals": ""
+      "signals": "Object.keys"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-prevent-extensions",
-      "signals": ""
+      "signals": "Object.preventExtensions"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-seal",
-      "signals": ""
+      "signals": "Object.seal"
     },
     {
       "name": "core-js-3-only-polyfill/es6-object-set-prototype-of",
@@ -529,7 +491,7 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-reflect-define-property",
-      "signals": ""
+      "signals": "Reflect.defineProperty"
     },
     {
       "name": "core-js-3-only-polyfill/es6-reflect-delete-property",
@@ -541,11 +503,11 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-reflect-get-own-property-descriptor",
-      "signals": "Reflect.getOwnPropertyDescriptor"
+      "signals": "Reflect.getOwnPropertyDescriptor, Reflect.get"
     },
     {
       "name": "core-js-3-only-polyfill/es6-reflect-get-prototype-of",
-      "signals": "Reflect.getPrototypeOf"
+      "signals": "Reflect.getPrototypeOf, Reflect.get"
     },
     {
       "name": "core-js-3-only-polyfill/es6-reflect-has",
@@ -569,7 +531,7 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-reflect-set-prototype-of",
-      "signals": "Reflect.setPrototypeOf"
+      "signals": "Reflect.setPrototypeOf, Reflect.set"
     },
     {
       "name": "core-js-3-only-polyfill/es6-set",
@@ -605,7 +567,7 @@
     },
     {
       "name": "core-js-3-only-polyfill/es6-string-trim",
-      "signals": ""
+      "signals": "String.prototype.trim"
     },
     {
       "name": "core-js-3-only-polyfill/es6-typed-array-buffer",

@connorjclark connorjclark requested a review from a team as a code owner April 9, 2020 01:53
@connorjclark connorjclark requested review from patrickhulce and removed request for a team April 9, 2020 01:53
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work! another carrot for the sourcemapping folks :)

lighthouse-core/audits/legacy-javascript.js Show resolved Hide resolved
lighthouse-core/audits/legacy-javascript.js Outdated Show resolved Hide resolved
lighthouse-core/audits/legacy-javascript.js Outdated Show resolved Hide resolved
@@ -28,6 +28,7 @@ const createArtifacts = (scripts) => {
};
return acc;
}, {}),
SourceMaps: [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we a unit test or two in here to exercise the deduplication piece and any other flow that isn't currently covered by the bash script?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Co-Authored-By: Patrick Hulce <patrick.hulce@gmail.com>
@connorjclark
Copy link
Collaborator Author

@patrickhulce bump :)

patrickhulce
patrickhulce previously approved these changes Apr 13, 2020
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

travis says legacy-javascript smoketest failed to produce a report though so I'm a little concerned what I'm missing :/

@connorjclark
Copy link
Collaborator Author

I'm not bothering to look until #10566 lands, maybe moot.

@@ -191,7 +76,8 @@ async function createVariant(options) {
fs.writeFileSync(`${dir}/.babelrc`, JSON.stringify(babelrc || {}, null, 2));
// Not used in this script, but useful for running Lighthouse manually.
// Just need to start a web server first.
fs.writeFileSync(`${dir}/index.html`, `<title>${name}</title><script src=main.bundle.min.js>`);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lack of closing script element = bad sad times w/ no debuggability in CDT. chrome still requests the script, still shows in Network as a script, yet never loads.

},
{
"name": "core-js-2-only-polyfill/es6-array-find",
"signals": "Array.prototype.find"
},
{
"name": "core-js-2-only-polyfill/es6-array-find-index",
"signals": "Array.prototype.findIndex"
"signals": "Array.prototype.findIndex, Array.prototype.find"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.prototype.find is a false positive

@@ -137,45 +29,33 @@
"name": "core-js-2-only-polyfill/es6-array-from",
"signals": "Array.from"
},
{
"name": "core-js-2-only-polyfill/es6-array-index-of",
"signals": ""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this were empty because legacy javascript never checked for these polyfills, because I omitted them intentionally. The duplication of the polys in the run.js script had some extra stuff. fixed now they it uses the same data source.

{
"name": "core-js-3-only-polyfill/es6-array-last-index-of",
"signals": "Array.prototype.lastIndexOf"
},
{
"name": "core-js-3-only-polyfill/es6-array-map",
"signals": ""
"signals": "Array.prototype.map"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example of the pattern matching not yielding results, but using source maps filled a gap.

},
{
"name": "core-js-3-only-polyfill/es6-array-reduce-right",
"signals": ""
"signals": "Array.prototype.reduce, Array.prototype.reduceRight"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another false positive. I think the map sources substring check is too loose.

// Skip if the pattern matching found a match for this polyfill.
if (matches.some(m => m.name === name)) continue;

const source = bundle.rawMap.sources.find(source => source.includes(module));
Copy link
Collaborator Author

@connorjclark connorjclark Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was avoiding endsWith here because I know that webpack sometimes adds ? to the end of things ... I don't know if that's actually true from a sane configuration and maybe that's not an issue.

@patrickhulce think we can just uses endsWith here`? should we try to strip anything after a question mark ?

Copy link
Collaborator Author

@connorjclark connorjclark Apr 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a86f324 fixed many false positives

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it need to be endsWith or something more like

new RegExp(`${module}($|\/|\\?)`

perhaps? these are the file names right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is the entire file path, resolvable in node. I don't think those slashes are needed. module is the name like es.array.fill and the node module is named ...es.array.fill.js.

I'm just unclear if sometimes there is a ? in webpack maps and if I should account for that.

@@ -1,238 +1,176 @@
core-js-2-only-polyfill
47738 es6-typed-uint8-clamped-array/main.bundle.min.js
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source map comments made everything bigger

@patrickhulce
Copy link
Collaborator

I'm a little unclear what the status is here @connorjclark. Marked as waiting on me so presumably the blockers were cleared, but the linked issue was an issue not a PR (but I guess its linked PR landed).

Are the current build failures expected? The only substantial change I see since my last review is the endsWith change I have an open question on :)

@connorjclark
Copy link
Collaborator Author

note: runner unit test is flaky in GH Run xvfb-run --auto-servernum yarn unit https://github.com/GoogleChrome/lighthouse/pull/10564/checks?check_run_id=613725231

@connorjclark
Copy link
Collaborator Author

I'm a little unclear what the status is here @connorjclark. Marked as waiting on me so presumably the blockers were cleared, but the linked issue was an issue not a PR (but I guess its linked PR landed).

Are the current build failures expected? The only substantial change I see since my last review is the endsWith change I have an open question on :)

Sorry, I jumped the gun there. It should be ready to land now. I commented a lot to explain why some changes happened.

@patrickhulce
Copy link
Collaborator

note: runner unit test is flaky in GH Run xvfb-run --auto-servernum yarn unit

maybe we should increase the timeout?

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@connorjclark connorjclark merged commit 80e24f1 into master Apr 27, 2020
@connorjclark connorjclark deleted the legacy-js-maps branch April 27, 2020 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants