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

Fallback resource timing in web workers #6721

Merged
merged 1 commit into from
Jun 4, 2018

Conversation

sbma44
Copy link
Member

@sbma44 sbma44 commented May 23, 2018

This PR adds a fallback method to collectResourceTiming: true for browsers that don't implement the performance.getEntries() method properly in web workers. It provides as much data as can be collected now, and should return full data when these browsers correct their implementations.

The availability of the performance API in web workers remains unpleasantly murky. Despite tickets like https://bugzilla.mozilla.org/show_bug.cgi?id=1425458 and badges declaring web worker availability bugs remain in major browsers. Specifically, it appears that in both Firefox and Safari performance.getEntries, performance.getEntriesByName and performance.getEntriesByType return empty arrays in web workers regardless of whether the worker has made network requests.

performance.mark, performance.measure and subsequent use of performance.getEntries* do work, however. This is an inferior solution, as PerformanceMeasure objects compare unfavorably to PerformanceResourceTiming objects:

  • no DNS, TLS or connection timing data
  • no division between request and response
  • no data on payload size

Still, the basic timing data that can be collected is better than nothing.

This change does not alter any codepaths when collectResourceTiming is false. When it is true, a check on array length and an invocation of performance.mark() are added to the status quo codepath. Obviously there's a bit more code for the fallback case, but it's pretty slight.

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs n/a
  • post benchmark scores
  • manually test the debug page tested on my instrumentile integration test page instead (GL JS debug page doesn't collect resource timing)

@sbma44 sbma44 force-pushed the fallback-resource-timing-in-web-workers branch from c654f50 to be008e2 Compare May 23, 2018 18:55
@sbma44
Copy link
Member Author

sbma44 commented May 23, 2018

Please let me know if you'd like to see benchmarks here -- I haven't bothered running them yet given how slight this change is.

Copy link
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

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

Can you DRY up the repeated code here / extract it to util/performance.js somehow?

.flowconfig Outdated
@@ -8,6 +8,7 @@
.*/node_modules/htmltojsx/.*
.*/node_modules/documentation/.*
.*/node_modules/module-deps/.*
.*/node_modules/bcryptjs/src/bower.json
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the rationale for this change? Doesn't look like bcryptjs is in the dependency tree.

Copy link
Contributor

Choose a reason for hiding this comment

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

I ran into something similar to this the other day when I was using npm install rather than yarn install. I can't say for sure that's where this was introduced but I kept getting a test error in bcrypt until I removed node modules and reinstalled with yarn. This shouldn't be needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's present in my node_modules after a fresh npm i and causes flow test failures thanks to some templating wackiness. Not related to this PR and I'm happy to do whatever's most appropriate here. Replicated with node 6 and 8.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tom, if you remove this line from .flowconfig then rm -rf node_modules and reinstall with yarn install does the bcrypt error go away?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, posted before refreshing to see @ryanhamley's comment. I see that yarn is the default here, if npm support isn't a consideration I'm happy to remove this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think npm install should work the way you expected it to. We need to debug why it isn't, but that's a separate issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

npm install doesn't use yarn.lock, so it installs a newer version of @mapbox/batfish, which pulls in bcryptjs via some transitive dependencies.

Let's revert here and consider using https://www.npmjs.com/package/use-yarn to avoid this gotcha in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ryanhamley yes, confirmed that using yarn avoids the problem

@jfirebaugh sounds good, I've removed the relevant commit

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened a ticket for the npm bug #6774

@sbma44 sbma44 force-pushed the fallback-resource-timing-in-web-workers branch from 2fea81b to ce293d6 Compare June 1, 2018 23:35
@sbma44
Copy link
Member Author

sbma44 commented Jun 1, 2018

Rebasing away the bower config commit did something weird to my last merge from master, prompting another merge and a strange-looking commit history in this PR. LMK if this is an issue and you need a fresh branch.

@jfirebaugh jfirebaugh force-pushed the fallback-resource-timing-in-web-workers branch from e705671 to 179214d Compare June 4, 2018 16:05
@jfirebaugh jfirebaugh merged commit 0faffa8 into master Jun 4, 2018
@jfirebaugh jfirebaugh deleted the fallback-resource-timing-in-web-workers branch June 4, 2018 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants