-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Lazy load intersection-checking should not be done in-parallel #5236
Comments
Why do you think 2 is preferable? Firefox will also do something akin to 1 as I understand it. cc @hiikezoe |
The reason I preferred (2) is because I remember there was some discussion on IRC about whether we should reuse intersection observer, or "piggy-back off of the async machinery" separately, and from what I remember Domenic preferred the latter, so I gathered that not depending on Intersection Observer might be the best way forward. If you think we should do (1), I can focus on that after we get the main Lazyload PR merged. |
Using intersection observer as our building block for all things "intersect the viewport" makes the most sense to me, but would be great to get @domenic's perspective too. |
My original semi-objection to using intersection observer is that it contains both more and less than I was hoping it would. In particular, the actual "does it intersect" step is vague: this algorithm step 4 delegates to this algorithm step 5: "intersecting it with the root intersection rectangle". That's no better than HTML's current "intersect the viewport", so when we initially we were trying to call out to the IO spec just to do a one-time determination of whether it intersects, I said we should stop doing that. We can just use the 1 core step, or its HTML equivalent, insteed of the surrounding 21 steps. This leaves the infrastructure for tracking and notifying about interesections. That consists of another ~30 steps that are mostly not useful for our use case; they do a lot of calculation and If we were writing this from scratch in the manner of (2) I think we would end up with a much shorter and cleaner algorithm, which does not manipulate a lot of platform objects, in order to queue the relevant task. If we go with (1) we're going to have a fun time creating synthetic So, with that all out of the way: probably (1) is still better, especially if that's the implementation plan. Creating two parallel systems just to avoid using the messy one is not a great strategy. And, there are some steps in the IO spec that are good to reuse. For example, the handling of clip-path, or nested browsing contexts if we extend this to iframes. So that's another argument for reuse, i.e. for (1). |
I see, I do agree with that. Perhaps IO should have a way for spec-level intersections that do not require as much non-spec infrastructure, so to say. We mostly care about there being a single place to define and expand on the intersection primitive and being in charge of relative ordering of algorithms to be invoked. |
Thanks a lot for the input. It looks (1) is the way to go, which means the
Regarding:
This would be great. Maybe once we get this done, we can summarize specifically what would be nice for HTML to not have to worry about, and file a bug on IntersectionObserver so it can expose something cleaner that meets our needs, and potentially the needs of future primitives that require the same thing. |
One complication came to mind if we try to do refactoring via (1), reusing the run-the-update-intersection-observations-steps in update-the-rendering-steps. The resumption of #updating-the-image-data is not just dependent on whether the image intersects the viewport. As currently specced, resumption is a function of (a) viewport intersection (b) loading attribute state (c) script-enabled-ness. It seems tricky to me to spec (1) in a way that also considers (b) and (c), because I think we'd end up having to add something to the update-the-rendering-steps anyways, that checks for conditions (b) and (c) every time. Any thoughts? |
I think (c) is constant so you can move that out. And when (b) changes you'd manipulate whether update-the-rendering checks for intersection or not, presumably? |
I was hoping that was the case.
Originally I was thinking we wouldn't directly respond to setting the |
Yeah. Probably have to double check that covers all code paths and what we want, but that's what I was thinking. |
Follow-up: #5236. Tests: * web-platform-tests/wpt#14914 * web-platform-tests/wpt#17985 * web-platform-tests/wpt#18087 * web-platform-tests/wpt#20634 * web-platform-tests/wpt#20747 * web-platform-tests/wpt#20683 * web-platform-tests/wpt#20774 * web-platform-tests/wpt#20680 * Some as part of https://bugzilla.mozilla.org/show_bug.cgi?id=1542784 Closes #2806. Closes #5250. Co-authored-by: Dominic Farolino <domfarolino@gmail.com> Co-authored-by: Anne van Kesteren <annevk@annevk.nl>
… [1] for lazy-loading. r=emilio [1] whatwg/html#5236 Differential Revision: https://phabricator.services.mozilla.com/D61433 --HG-- extra : moz-landing-system : lando
… [1] for lazy-loading. r=emilio [1] whatwg/html#5236 Differential Revision: https://phabricator.services.mozilla.com/D61433
… [1] for lazy-loading. r=emilio [1] whatwg/html#5236 Differential Revision: https://phabricator.services.mozilla.com/D61433 UltraBlame original commit: 7c714a35e683539306e258969da6c10eb61cc80b
… [1] for lazy-loading. r=emilio [1] whatwg/html#5236 Differential Revision: https://phabricator.services.mozilla.com/D61433 UltraBlame original commit: 7c714a35e683539306e258969da6c10eb61cc80b
… [1] for lazy-loading. r=emilio [1] whatwg/html#5236 Differential Revision: https://phabricator.services.mozilla.com/D61433 UltraBlame original commit: 7c714a35e683539306e258969da6c10eb61cc80b
From #5236 (comment):
Currently the decision to defer an image load takes into consideration both the This is nice, because it means an in-viewport With this, I'd like to know if it seems reasonable to make the attachment of a synthetic intersection observer conditional only on the |
I think that is very reasonable. So the effect would be that a |
Yep |
That also matches our implementation as far as I can tell. |
Fixes #5236. Co-authored-by: Dominic Farolino <domfarolino@gmail.com>
This is a follow-up issue for #3752 (comment). Basically it seems not great that we keep running the will lazy load image steps, which access main-thread state, from an in-parallel context. I see two ways around this:
Creating something new (the second proposal above) is probably preferable, but might have a very small compat impact. Chrome currently implements lazy-loaded images and iframes with an intersection observer under the hood. Since the "new" steps that we'd add to the update-the-rendering-steps would run at a different time than the run-the-update-intersection-observations-steps, I wonder if it would be possible to observe this (that is, observe the ordering between IO callbacks and image load resumption).
@annevk What do you think about (2) above?
The text was updated successfully, but these errors were encountered: