-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Optimize preconnect callbacks #23557
Conversation
9b8676a
to
dda1360
Compare
@@ -102,7 +101,13 @@ export class AmpFlyingCarpet extends AMP.BaseElement { | |||
}); | |||
if (this.firstLayoutCompleted_) { | |||
this.scheduleLayout(this.children_); | |||
listen(this.element, AmpEvents.BUILT, this.layoutBuiltChild_.bind(this)); | |||
this.children_.forEach(child => { |
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.
This isn't equivalent. We're listening for new children to be added to the flying carpet, not for already know children to upgrade. "Necessary since not all children will be built by the time the flying-carpet has its #layoutCallback called."
Let's split this into a separate PR.
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.
Added possibly more complete impl. to #23767
3dabafd
to
d863b6b
Compare
src/service/timer-impl.js
Outdated
delete this.delayQueue_[delay]; | ||
|
||
for (let i = 0; i < callbacks.length; i++) { | ||
const cb = callbacks[i]; |
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.
This needs to be wrapped in a try-catch, since any cb
could throw.
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.
This cb is already wrapped in a try-catch before being pushed to the queue, or am I missing something?
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 this approach is going to work in practice, because it relies on the calls coming in the same milli second and has the additional downside that individual callbacks are no longer scheduled as tasks.
I think this might be as simple as replacing the timer.delay
call with startupTask
c51e054
to
e53519d
Compare
Which is the use case from #22975. But it's not just in the same ms, it's scheduled to run at the same ms. So
What's the downside here? It'll require a try-catch, but this should work fine. |
26c084c
to
bf101f6
Compare
Downside is that e.g. user actions cannot interrupt execution. |
1e8a396
to
56b6385
Compare
56b6385
to
4fd50dc
Compare
Ready for another review 👍 |
4fd50dc
to
87a4a95
Compare
87a4a95
to
a6463ff
Compare
* batch preconnects and clean AmpEvents.BUILT * fix conflict * fix call * types * change debounce to 1ms, polish comments * revert commits * feedback * don't return timeout id * fix jsdoc * replace delay call with startupchunk * revert type changes * whitelist startupchunk * fix conflicts * fix test * add fortesting * fix test: force macrotask before checking if preconnect was called
Closes #22975
Before:
After (using
startupChunk
):