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

🚀 [amp-story-player] Wait for first story to load before loading next ones #29703

Merged
merged 13 commits into from
Sep 1, 2020

Conversation

Enriqe
Copy link
Contributor

@Enriqe Enriqe commented Aug 5, 2020

Fixes #29320

Loading 2 iframes initially involved a lot of changes (because of how other methods like show() expect there to be 3 iframes) so I'm sending those in a follow up. (Tracked #29706)

As seen on the first table, having a story specific event that delays the subsequent stories from being loaded makes the initial load time of the current story shorter.

Time for first story page to be loaded

current storyLoaded documentLoaded
normal 1.88s 1.37s (Δ -27.13%) 1.74s (Δ -7.45%)
fast 3G ~72s ~30s (Δ -58.33%) ~34s (Δ -52.78%)

There is a downside though, loading subsequent stories take longer to finish pre-rendering.

Time for secondary stories to be pre-rendered

current new
normal 3.17s 4.14s (Δ +30.6%)
fast 3G ~77s ~97s (Δ +25.97%)

Quick calculations using different network connection emulations and with the same player sample page containing local stories.

@Enriqe Enriqe requested a review from gmajoulet August 5, 2020 23:32
@google-cla google-cla bot added the cla: yes label Aug 5, 2020
@amp-owners-bot
Copy link

amp-owners-bot bot commented Aug 5, 2020

Hey @gmajoulet, @newmuis! These files were changed:

extensions/amp-story/1.0/amp-story.js

@gmajoulet
Copy link
Contributor

I filed this ticket for the followup to make it easier to track: #29706

extensions/amp-story/1.0/amp-story.js Outdated Show resolved Hide resolved
src/amp-story-player/amp-story-player-impl.js Outdated Show resolved Hide resolved
@Enriqe
Copy link
Contributor Author

Enriqe commented Aug 12, 2020

  • Added some metrics/calculations in PR description that measures the effects of this change.
  • Added functionality to handle edge case where user swipes before first story is loaded.

Re. event name: Considering that having an amp-story specific message is faster than using documentLoaded , we should use that instead. We should probably change the name to stick with the existing event names: maybe storyLoaded?

updateCurrentIframe_(story) {
const iframeIdx = story[IFRAME_IDX];
const iframeEl = this.iframes_[iframeIdx];
this.layoutIframe_(story, iframeEl, VisibilityState.VISIBLE).then(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This layoutIframe_ is a preventive operation in case the user swiped to navigate before this new current story started its layoutIframe_ (because it was waiting for the first story to load).

@Enriqe
Copy link
Contributor Author

Enriqe commented Aug 17, 2020

Friendly ping

extensions/amp-story/1.0/amp-story.js Outdated Show resolved Hide resolved
* @private
*/
waitForStoryToLoadPromise_(iframeIdx) {
return new Promise((resolve) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you decide to not implement a timeout because of the fallback you have where if the user navigates to the next story it still loads properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So do you mean like returning Promise.race([promise, timeout]) where timeout is a Promise resolved by the next story when navigated to it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but I don't know if it's a good idea since it'd mean you're on a device that's struggling with the first story load, and you'd start loading the second one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I thought about it but decided not to do it because when navigating it would cause slower loading times for the new story.

E.g.

  1. We have the initial load of the 1st, 2nd, and 3rd stories.
  2. User navigates, 1st story is still not finished loading
  3. Player resolves timeout; making 2nd and 3rd story to start loading.

This would make the 2nd story load slower, because it would be loading at the same time as the 3rd story.

src/amp-story-player/amp-story-player-impl.js Outdated Show resolved Hide resolved
src/amp-story-player/amp-story-player-impl.js Outdated Show resolved Hide resolved
src/amp-story-player/amp-story-player-impl.js Outdated Show resolved Hide resolved
@Enriqe Enriqe force-pushed the improve-iframe-loading branch from af760b2 to 05b6372 Compare August 21, 2020 22:57
@Enriqe
Copy link
Contributor Author

Enriqe commented Aug 26, 2020

PTAL

@Enriqe
Copy link
Contributor Author

Enriqe commented Aug 28, 2020

Friendly ping

@Enriqe
Copy link
Contributor Author

Enriqe commented Aug 31, 2020

@gmajoulet friendly ping

Copy link
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

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

Really robust slow network/error handling 👍

src/amp-story-player/amp-story-player-impl.js Outdated Show resolved Hide resolved
@Enriqe Enriqe merged commit 5247739 into ampproject:master Sep 1, 2020
ed-bird pushed a commit to ed-bird/amphtml that referenced this pull request Dec 10, 2020
… ones (ampproject#29703)

* wait for first story to load before loading next ones

* address edge case where user swipes before subsequent stories are laid out

* add private

* typo

* change event name

* remove preventive layout for previous iframe, since by definition it should have been laid out already

* add unit test for edge case

* cleanups

* fix types

* renaming, clean up by calling cacheUrl once

* reject previous promises

* weird merge but ok

* condense into one deferred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[amp-story-player] PE: improve loading strategy
3 participants