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

Workspace: InOb-based load scheduler #31591

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dvoytenko
Copy link
Contributor

@dvoytenko dvoytenko commented Dec 14, 2020

Partial for #31915.

This is an alternative to intersect-resources launch, but it address the following key goals:

  1. It makes element-by-element launch possible. E.g. failures in ads wouldn't block other elements.
  2. It eliminates need for any measurements in the loading path.
  3. It recentralizes API slightly around the custom element, thus reducing differences between AMP, Bento, FIE, and in-a-box.
  4. This change should help us speed up removal of other measurement APIs.
  5. Immediately eliminates the need of owner for most of cases.

Key implementation notes:

  • The main theme: all the scheduling/loading code is extracted from the Resources class and moved to the LoadScheduler.
  • Load scoring and timeouts are left mostly unchanged from the current version.
  • It's implemented via a set of IntersectionObservers, each got different ranges of loading: 1 viewport, 3 viewports, etc.
  • Only elements that return true from isLoadableV2 go into this loading path.

TODO:

  • Update inabox resource manager
  • Tests
  • Improve docs

@lgtm-com
Copy link

lgtm-com bot commented Dec 14, 2020

This pull request introduces 1 alert when merging 2db1d1e into 3a31bb2 - view on LGTM.com

new alerts:

  • 1 for Missing 'this' qualifier

@lgtm-com
Copy link

lgtm-com bot commented Jan 12, 2021

This pull request introduces 1 alert when merging 337e8e9 into e1e8a4c - view on LGTM.com

new alerts:

  • 1 for Missing 'this' qualifier

@dvoytenko dvoytenko marked this pull request as ready for review January 13, 2021 01:31
@dvoytenko
Copy link
Contributor Author

Switching this to draft to look into deferred build approach.

@dvoytenko dvoytenko marked this pull request as draft January 14, 2021 22:05
@samouri
Copy link
Member

samouri commented Jan 15, 2021

would this help get rid of child-layout-manager? Would help with various layout issues, like #30719

@dvoytenko
Copy link
Contributor Author

Could we get rid of child-layout-manager? Would help with various layout issues, like #30719

That'd probably be resolved with #31948

*
* @return {!Promise|undefind}
*/
loadCallback() {
Copy link
Member

@samouri samouri Jan 15, 2021

Choose a reason for hiding this comment

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

I feel that this (and build/layout) should not have callback in their names. I gave the full reasoning here #31046 (comment). The tldr is that we are asking an element to load as opposed to informing it that load has happened.

I understand the desire to match CE's naming scheme, but IMO it doesn't make sense for these methods

@@ -396,6 +409,15 @@ function createBaseCustomElementClass(win) {
return this.signals_.whenSignal(CommonSignals.BUILT);
}

/**
* Returns the promise that's rewsolved when the element has been loaded.
Copy link
Member

Choose a reason for hiding this comment

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

nit: rewsolved --> resolved

@@ -877,6 +905,9 @@ function createBaseCustomElementClass(win) {
/** @private */
connected_() {
if (this.built_) {
if (this.isLoadableV2()) {
Copy link
Member

@samouri samouri Jan 15, 2021

Choose a reason for hiding this comment

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

Isn't one of the big points here that we don't need to branch on isBuilt() anymore? I.e. scheduleLoad can be extracted from the condition since the definition of load() is build().then(() => this.layout()))

@@ -1226,6 +1256,9 @@ function createBaseCustomElementClass(win) {
const isReLayoutNeeded = this.implementation_.unlayoutCallback();
Copy link
Member

Choose a reason for hiding this comment

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

nit: isReLayoutNeeded --> isRelayoutNeeded

const {win} = this.ampdoc_;
const opts = {
root: win.document,
rootMargin: `${range * 100}% ${range * 25}%`,
Copy link
Member

@samouri samouri Jan 15, 2021

Choose a reason for hiding this comment

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

can you explain the horizontal margin?


// Unschedule to reschedule with the new parameters.
if (this.tasks_.has(id)) {
this.unschedule_(resource, /* canceled */ true);
Copy link
Member

Choose a reason for hiding this comment

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

Should the be canceled=false?

@@ -672,6 +700,9 @@ export class Resource {
* @return {!../layout-rect.LayoutRectDef}
*/
getLayoutBox() {
if (this.loaderRectV2_) {
Copy link
Member

Choose a reason for hiding this comment

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

Does v2 not need to manually move fixed elements? What about intersect-resources?

@dvoytenko dvoytenko changed the title InOb-based load scheduler Workspace: InOb-based load scheduler Mar 22, 2021
@jridgewell jridgewell removed their request for review August 31, 2022 21:02
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Dima Voytenko seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

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