-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add Async Runner for News Site Next Testing #442
base: main
Are you sure you want to change the base?
Conversation
resources/benchmark-runner.mjs
Outdated
@@ -315,12 +334,35 @@ class RAFTestInvoker extends TestInvoker { | |||
} | |||
} | |||
|
|||
class AsyncRAFTestInvoker extends BaseRAFTestInvoker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The semantics here are tricky, but great to be opening this discussion. @smaug---- @rniwa the current behavior is
requestAnimationFrame(() => this._syncCallback());
requestAnimationFrame(() => {
setTimeout(() => {
this._asyncCallback();
setTimeout(async () => {
await this._reportCallback();
resolve();
}, 0);
}, 0);
});
Since we'd now need to await for _syncCallback in a world with async steps, this new behavior wraps the second rAF into the first rAF's callback (after awaiting for the sync step to finish). Is this how you envision measuring async steps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wonder if it would be feasible to make an "in place" change where, rather than having separate AsyncRAFTestInvoker & AsyncTimerTestInvoker & AsyncSuiteRunner classes, we
(a) update the existing ones to await in the appropriate places
(b) change the existing _runTestAndRecordResults
to await test.run(this._page);
(c) allow tests to opt in to the behavior by simply passing async functions into the BenchmarkTestStep
rather than setting a type and switching which classes are used.
Obviously this would rely on us being happy with the core async measurement loop, and would change the overall timing & semantics by awaiting on non-promises. But it would also be quite a bit simpler and may allow use cases for v4 where tests have one step that's async and others that aren't.
resources/benchmark-runner.mjs
Outdated
_scheduleCallbacks(resolve) { | ||
requestAnimationFrame(async () => { | ||
await this._syncCallback(); | ||
requestAnimationFrame(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this work rather badly in those tests where the sync part is really fast. There would be idle time between the rAF calls, and thus the measured time would also include idle time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smaug---- any idea how we could prevent this, while still waiting for the syncCallback ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would get messy, but we could perhaps have another rAF callback right before _syncCallback call.
That new one should fire at the same tick as the one which _syncCallback() uses (assuming I guess correctly how it schedules new work.) The new raf callback would start async time.
In addition to that we'd need a setTimeout(,0) to stop the sync time - that would be used in case there is time to run setTimeout(,0) between the relevant ticks. But the sync time might also just stop when the next raf starts - the order of rAFs and setTimeout can be anything.
(Of course currently there isn't such thing as "stop sync time", there is just starting async time)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smaug---- honestly, I don't fully follow the above, but here are some additional thoughts.
The following would keep the two sequential rafs, but would enable workloads that might take longer to resolve the promise of the _syncCallback
. Feels 'old school', but works in my initial testing in Chrome:
_scheduleCallbacks(resolve) {
const checkedIn = {
__proto__: null,
sync: false,
async: false,
};
const checkin = async (type) => {
checkedIn[type] = true;
if (checkedIn.sync && checkedIn.async){
setTimeout(() => {
this._asyncCallback();
setTimeout(async () => {
await this._reportCallback();
resolve();
}, 0);
}, 0);
}
};
requestAnimationFrame(async () => {
await this._syncCallback();
checkin("sync");
});
requestAnimationFrame(() => {
checkin("async");
});
}
Yet another though: do we even need two rafs, or could we do something simpler.
If we're awaiting a Promise, which is a microtask with higher priority, can we follow that with a setTimeout directly?
requestAnimationFrame(async () => {
await this._syncCallback();
setTimeout(() => {
this._asyncCallback();
setTimeout(async () => {
await this._reportCallback();
resolve();
}, 0);
}, 0);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smaug---- honestly, I don't fully follow the above,
Not surprised, it is confusing :) Basically what I was thinking is to try to detect when the sync time ends, explicitly.
And then not count the time between sync end and and async start as measured time.
setTimeout after _syncCallback would bring back the same issues sp2 has. There some random animation ticks may or may not run during measured time, because it is relying on setTimeout and not rAF callbacks.
Assuming react uses postMessage similarly to setTimeout(0),
So basically require both postMessage and setTimeout to be processed. Looks like there is a message channel and its port is used for communication |
I assume the MessageChannel is from the React framework? - I'd need to dig in a little more though... It probably depends, if we're trying to fix the React workloads, or if we're trying to allow async test steps. For the later, we'd need to |
The MessageChannel in my example is from HTML spec. |
Summarizing an offline conversation I had with @smaug---- :
|
And hopefully use of MessageChannel really helps. The idea isn't tested yet ;) |
@@ -18,6 +18,30 @@ export class TestRunner { | |||
this.#frame = frame; | |||
} | |||
|
|||
get frame() { | |||
return this.#frame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since i'm extending and overriding the runTest function, I had to create getters for the private variables.
just more boilerplate..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are now external consumers for these, should we just make them public? cc @rniwa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only using getters at the moment, so more boilerplate, but maybe more "secure" than just making them public? 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to making the public and lower overhead.
@@ -100,5 +100,6 @@ class RemoteSuiteRunner extends SuiteRunner {} | |||
export const SUITE_RUNNER_LOOKUP = { | |||
__proto__: null, | |||
default: SuiteRunner, | |||
async: SuiteRunner, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to create a new SuiteRunner, since only the TestRunner is different and that's dynamically selected.
@@ -24,7 +24,24 @@ export class TimerTestInvoker extends TestInvoker { | |||
} | |||
} | |||
|
|||
export class RAFTestInvoker extends TestInvoker { | |||
class AsyncTimerTestInvoker extends TestInvoker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we plan to use both the timer and RAF invoker for async? I had a sense that we kept the sync timer invoker around for backwards compat or non-default testing environments.
I'm assuming the overall properties are quire different once we are async (potentially reducing utility of timer), and it's complex enough to reason about one implementation, so should we consider just having one and exposing it on both the default and non-default configuration?
I'm open to having both but would like to find ways to reduce the amount of work if possible :). @camillobruni @smaug---- @rniwa thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be fine to drop the setTimeout approach altogether since we haven't really discovered additional issues with it?
@@ -18,6 +18,30 @@ export class TestRunner { | |||
this.#frame = frame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's not use private properties, they add needless overhead in the runner. The runner code should aim at maximum performance and minimal startup costs.
Last I tested this is measurable in Firefox and Chrome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should restrict ourselves from using new ECMAScript features. With that argument, we should be going back to writing ES5 code without any classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is performance penalty attached to it for the test runner, then yes, we should restrict ourselves, we should aim at the lowest possible overhead there. Especially if it uses code that is not popular out in the wild.
And I would even agree that we should transpile and minify to ES5 the runner code for a big part for performance reasons!
It's a different story for workloads though, a good mix of old and new features is very welcome.
Note: we did not include the latest framework versions based on this groups feedback... so there is precedence for going equally the other way.
@@ -18,6 +18,30 @@ export class TestRunner { | |||
this.#frame = frame; | |||
} | |||
|
|||
get frame() { | |||
return this.#frame; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to making the public and lower overhead.
A potential solution to: #441
This pr adds an Async Runner, which waits for each test.run() to complete.
Tests for comparison:
3. NewsSite-Delay - async runner with a 500ms delay, before the test resolvescrossbench scores