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(predictive-perf): refactor simulation logic #3489

Merged
merged 5 commits into from
Oct 11, 2017

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Oct 5, 2017

Addresses the remaining non-accuracy impacting items from code review.

  • Moves to use WebInspector.resourceTypes
  • Moves the bulk of the logic into lib/
  • Renames estimator -> simulator
  • Eliminates estimateGraph method from PageDependencyGraph artifact class
  • Renames the node states in Simulator
  • Refactors signature of simulateDownloadUntil

TODO from #3162 (comment) (Separately with analysis of impact to accuracy)

  • Use all trace events that have a stack trace
  • Improve the network initiator logic
  • Remove safeguards in favor of isValidDepGraph

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

this works for me! only one small nit

* @return {{timeElapsed: number, roundTrips: number, bytesDownloaded: number, congestionWindow: number}}
*/
simulateDownloadUntil(bytesToDownload, timeAlreadyElapsed = 0, maximumTimeToElapse = Infinity) {
simulateDownloadUntil(bytesToDownload, options) {
options = Object.assign({
Copy link
Member

Choose a reason for hiding this comment

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

can we destructure AND do default values?

based on http://node.green/ i think we're good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

totes

@patrickhulce
Copy link
Collaborator Author

@brendankenny did you want a whack at this too, or you good?

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.

just a few style nits but otherwise LGTM

@@ -123,13 +126,13 @@ class PredictivePerf extends Audit {
let sum = 0;
const values = {};
Object.keys(graphs).forEach(key => {
const estimate = PageDependencyGraph.estimateGraph(graphs[key]);
const lastLongTaskEnd = PredictivePerf.getLastLongTaskEndTime(estimate.nodeTiming);
const results = new Simulator(graphs[key]).simulate();
Copy link
Member

Choose a reason for hiding this comment

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

I'd personally still prefer estimate for the local var here, as results is information-less :) or simulatedResults or something. results could be anything

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

@@ -7,8 +7,9 @@

const Audit = require('./audit');
const Util = require('../report/v2/renderer/util.js');
const PageDependencyGraph = require('../gather/computed/page-dependency-graph.js');
const Node = require('../gather/computed/dependency-graph/node.js');
const Simulator = require('../lib/dependency-graph/simulator/simulator.js');
Copy link
Member

Choose a reason for hiding this comment

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

I guess simulator.js's context can be figured out from its path, but maybe LoadSimulator or something for the local handle to it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sg done

this._connectionsInUse = new Set();
this._numberInProgressByType = new Map();

this._nodes = {};
Copy link
Member

Choose a reason for hiding this comment

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

should be an array now?

Copy link
Collaborator Author

@patrickhulce patrickhulce Oct 9, 2017

Choose a reason for hiding this comment

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

wait why? I thought the whole point was to key these by their state 😆

EDIT: oh just that the keys are numbers now so you'd prefer to have array?

Copy link
Member

Choose a reason for hiding this comment

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

EDIT: oh just that the keys are numbers now so you'd prefer to have array?

yah

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

@@ -320,8 +328,10 @@ class Estimator {
const connection = this._connections.get(node.record.connectionId);
const calculation = connection.simulateDownloadUntil(
node.record.transferSize - timingData.bytesDownloaded,
timingData.timeElapsed,
timePeriodLength - timingData.timeElapsedOvershoot
{
Copy link
Member

Choose a reason for hiding this comment

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

wait, why is this moving to an options object? There's only three and having them named doesn't seem better in this case...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel ya @brendankenny, but @paulirish was persistent

executive summary: it's easier for the caller to understand what the params are

@patrickhulce patrickhulce changed the title refactor(predictive-perf): remaining review items refactor(predictive-perf): address remaining review items Oct 9, 2017
@patrickhulce patrickhulce changed the title refactor(predictive-perf): address remaining review items core(predictive-perf): remaining review items Oct 9, 2017
@patrickhulce patrickhulce changed the title core(predictive-perf): remaining review items core(predictive-perf): refactor simulation logic Oct 9, 2017
@brendankenny
Copy link
Member

rebase to pick up test fixes?

* Moves gather/computed/dependency-graph to lib/dependency-graph
* Renames estimator -> simulator
* Eliminates estimateGraph method from PageDependencyGraph artifact class
* Renames the node states in Simulator
* Refactors signature of simulateDownloadUntil
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.

None yet

3 participants