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

MWPW-167716 Remove await from both gnav and georouting #3680

Open
wants to merge 1 commit into
base: stage
Choose a base branch
from

Conversation

sharmrj
Copy link
Contributor

@sharmrj sharmrj commented Feb 13, 2025

This is the first second of four five PRs (the first is #3720) aimed at improving Global-Navigation performance. This first PR does not directly affect the global-navigation (or georouting), but is rather aimed at improving the load times of the sections after the first one. For more information look at the discussion #3558

The first section is assumed to be LCP and is prioritized. After the first section we load a series of features/blocks, among them georouting and global-navigation. Since we await both of these blocks, the subsequent sections cannot continue until they stop blocking the main thread.

This can be bad because the user cannot see the rest of the page, or even scroll, until the subsequent sections load. The affect of this poor UX is not something we measure but it is important nonetheless. And even though we assume LCP should be in the first section, in practice it is not always.

The solution is then to remove the awaits on the global-navigation and georouting. The effects of this change have been documented in the discussion #3558.

Resolves: MWPW-167716

Test URLs:

Copy link
Contributor

aem-code-sync bot commented Feb 13, 2025

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run PSI checks
  • Re-sync branch
Commits

Copy link
Contributor

aem-code-sync bot commented Feb 13, 2025

Page Scores Audits Google
📱 /?martech=off PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ /?martech=off PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

}
const header = document.querySelector('header');
if (header) {
header.classList.add('gnav-hide');
await loadBlock(header);
loadBlock(header);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any influence on CLS if you do this? Also what happens in terms of personalization? What if that loads before the GNAV?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No there's no CLS.
AFAICT if personalization must load it will load before either gnav or georouting; either right before georouting in loadPostLCP or in checkForPageMods. In both cases it is awaited. There is some personalization that takes place inside the gnav, but simply removing the await does not affect it in any way.

@@ -1192,13 +1192,15 @@ async function loadPostLCP(config) {

const georouting = getMetadata('georouting') || config.geoRouting;
if (georouting === 'on') {
const { default: loadGeoRouting } = await import('../features/georoutingv2/georoutingv2.js');
await loadGeoRouting(config, createTag, getMetadata, loadBlock, loadStyle);
import('../features/georoutingv2/georoutingv2.js')
Copy link
Contributor

Choose a reason for hiding this comment

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

Given @vhargrave concerns in the discussion, I suppose this was brought up with the georouting PM?

Copy link
Contributor

This pull request is not passing all required checks. Please see this discussion for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR.

@sharmrj
Copy link
Contributor Author

sharmrj commented Feb 14, 2025

To give an idea of what this change accomplishes, it essentially schedules our network requests postLCP more efficiently. As a visual representation, consider the below screen shot of our page load currently.

Screenshot 2025-02-14 at 9 25 54 AM

We see that many network requests are chained, blocking further requests until they are received. Specifically there's a visible bottleneck in the middle there. That happens to be georouting and global-navigation. See the trace here:
Trace-20250214T092251.json.zip

Now with the change in this PR:

Screenshot 2025-02-14 at 9 25 19 AM trace:

Trace-20250214T092719.json.zip

We can see that the bottleneck is gone. By removing just these two awaits we'll see fewer gaps in how our code and, subsequently, our network requests are scheduled (This is what I mean by scheduling more efficiently).

@salonijain3 salonijain3 added the high-impact Any PR that may affect consumers label Feb 17, 2025
Copy link
Contributor

@vhargrave vhargrave left a comment

Choose a reason for hiding this comment

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

see comments

@@ -1192,13 +1192,15 @@ async function loadPostLCP(config) {

const georouting = getMetadata('georouting') || config.geoRouting;
if (georouting === 'on') {
const { default: loadGeoRouting } = await import('../features/georoutingv2/georoutingv2.js');
await loadGeoRouting(config, createTag, getMetadata, loadBlock, loadStyle);
import('../features/georoutingv2/georoutingv2.js')
Copy link
Contributor

Choose a reason for hiding this comment

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

If you haven't done the performance enhancement we discussed for the georouting, then please confirm that this delay was tested and discussed with the georouting PM.
Otherwise please at least do the enhancement that was discussed (kicking off the loading of the .json file here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've tagged them on JIRA, and we'll continue the conversation there.
I looked into doing that optimization here, but I think it would fit well as its own PR. I'd prefer to keep the PRs as granular as we can. If you prefer I can make it the very next optimization we do.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that, but I can't approve a change to the load time of the georouting that goes live if you haven't approved it with the georouting PM or mitigated it with the change we discussed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I've raised a separate PR to optimize georouting first and then we can merge this one. Here's the PR @vhargrave : #3720

}
const header = document.querySelector('header');
if (header) {
header.classList.add('gnav-hide');
await loadBlock(header);
loadBlock(header);
header.classList.remove('gnav-hide');
}
loadTemplate();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a must, but i bet you could kick the loading of the fonts.js at the beginning of the postLCP somewhere and only await it here.. That would probably also give you some great savings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high-impact Any PR that may affect consumers needs-verification PR requires E2E testing by a reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants