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(fr): prepare emulation utilities for shared use #12375

Merged
merged 3 commits into from
Apr 21, 2021

Conversation

patrickhulce
Copy link
Collaborator

Summary
Broken out of #12366, just the emulation shared pieces. We already basically had this split in lib/emulation.js so it was just moving the last two methods that put it together :)

Related Issues/PRs
ref #11313 #12366

@patrickhulce patrickhulce requested a review from a team as a code owner April 19, 2021 16:41
@patrickhulce patrickhulce requested review from connorjclark and removed request for a team April 19, 2021 16:41
@google-cla google-cla bot added the cla: yes label Apr 19, 2021
Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

Worth bikeshedding for a minute? Maybe not, considering the improvement already here over the status quo :)

But:

emulate()

throttle() // Network and CPU
clearThrottling() // Network and CPU

enableNetworkThrottling()
clearNetworkThrottling()

enableCPUThrottling()
clearCPUThrottling()

enableThrottling() to match clearThrottling/enableNetworkThrottling/enableCPUThrottling? Or were you thinking in terms of matching emulate()?

@@ -129,7 +130,8 @@ class GatherRunner {
log.time(status);
const resetStorage = !options.settings.disableStorageReset;
await driver.assertNoSameOriginServiceWorkerClients(options.requestedUrl);
await driver.beginEmulation(options.settings);
await emulation.emulate(driver.defaultSession, options.settings);
await emulation.throttle(driver.defaultSession, options.settings);
Copy link
Member

Choose a reason for hiding this comment

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

this is a literal translation of the existing driver.beginEmulation, but could we not throttle here since per-pass throttling is going to be set regardless? I don't think there's any reason to set it here, at least.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, SG

Comment on lines +52 to +53
// TODO(FR-COMPAT): reconsider if this should be resetting anything
if (settings.throttlingMethod !== 'devtools') return clearNetworkThrottling(session);
Copy link
Member

Choose a reason for hiding this comment

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

seems more like a gather-runner concern than an emulation utility. Could we move out to there and keep this a little more separated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My response here is tightly related to my reflection on the poll so I'll respond to both here.

enableThrottling won the informal poll, so we'll rename throttle to that

Looking at this more closely, I don't think enableThrottling is right. The emulate and throttle methods aren't blindly turning on the emulation/throttling protocol methods, they're looking at config settings and setting what needs to be set according to the config settings.

A new method called enableThrottling that accepts the throttling object from settings that just calls the two makes sense, but at that point honestly why bother having a method at all?

I think your argument @brendankenny is that this logic should move up a layer into gather-runner but one of the goals here explicitly was to extract the shared parts for FR and at least for now all of this should be shared logic. Given that, I'm not sure I agree there's a benefit to having this live one layer up (it's not like we're mixing in the passConfig object like we were previously, there I wholeheartedly agree it shouldn't live in shared lib/).

Copy link
Member

Choose a reason for hiding this comment

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

Looking at this more closely, I don't think enableThrottling is right.

conveniently realized after the vote is closed :P

A new method called enableThrottling that accepts the throttling object from settings that just calls the two makes sense, but at that point honestly why bother having a method at all?

Ha, you wouldn't have to twist my arm on this if this is the direction you actually wanted to go ;) The clear*Throttling methods are basically already there.

I think it's the fact that it's exactly the same condition as if (passConfig.useThrottling) emulation.throttle(); else emulation.clearThrottling(); that ran right before this line that trips me up. If I were writing this as new code but wanted to match current behavior, I would go with if (passConfig.useThrottling && settings.throttlingMethod === 'devtools') ... in the caller in this case (which matches the pass-centric view "in this pass, enable throttling if throttlingMethod is 'devtools' and it's enabled for this pass").

I can easily see the arguments you're making here too, though, so this seems good to go. From the TODO(FR-COMPAT) and WPT-compat comments, those conditions might not end up doing the same thing anyways.

Copy link
Collaborator Author

@patrickhulce patrickhulce Apr 21, 2021

Choose a reason for hiding this comment

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

I would go with if (passConfig.useThrottling && settings.throttlingMethod === 'devtools')

I'm fine with that. Deal. You had me convinced until I looked at the code again, it's not the same condition! See below

Copy link
Collaborator Author

@patrickhulce patrickhulce Apr 21, 2021

Choose a reason for hiding this comment

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

Wait nevermind it's not the same condition, that's why I was putting this fight up in the first place :P

It's super specific that we only clear the network but not the CPU when we're doing other throttlingMethods. If that changes in FR I'm happy to move toward your suggestion, but for now that super specific detail feels like it should stay with throttle

Copy link
Member

Choose a reason for hiding this comment

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

It's super specific that we only clear the network but not the CPU when we're doing other throttlingMethods. If that changes in FR I'm happy to move toward your suggestion, but for now that super specific detail feels like it should stay with throttle

oh right, lord. We need to clear up what's going on with that :)

@patrickhulce
Copy link
Collaborator Author

patrickhulce commented Apr 19, 2021

enableThrottling won the informal poll, so we'll rename throttle to that but looking closer I really don't think that's an accurate name, see discussion above.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +52 to +53
// TODO(FR-COMPAT): reconsider if this should be resetting anything
if (settings.throttlingMethod !== 'devtools') return clearNetworkThrottling(session);
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this more closely, I don't think enableThrottling is right.

conveniently realized after the vote is closed :P

A new method called enableThrottling that accepts the throttling object from settings that just calls the two makes sense, but at that point honestly why bother having a method at all?

Ha, you wouldn't have to twist my arm on this if this is the direction you actually wanted to go ;) The clear*Throttling methods are basically already there.

I think it's the fact that it's exactly the same condition as if (passConfig.useThrottling) emulation.throttle(); else emulation.clearThrottling(); that ran right before this line that trips me up. If I were writing this as new code but wanted to match current behavior, I would go with if (passConfig.useThrottling && settings.throttlingMethod === 'devtools') ... in the caller in this case (which matches the pass-centric view "in this pass, enable throttling if throttlingMethod is 'devtools' and it's enabled for this pass").

I can easily see the arguments you're making here too, though, so this seems good to go. From the TODO(FR-COMPAT) and WPT-compat comments, those conditions might not end up doing the same thing anyways.

@GoogleChrome GoogleChrome deleted a comment Apr 20, 2021
@GoogleChrome GoogleChrome deleted a comment Apr 20, 2021
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.

4 participants