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

perf: use an interstitial page to load popup.html; load scripts using defered script tags #26555

Merged
merged 4 commits into from
Aug 28, 2024

Conversation

davidmurdoch
Copy link
Contributor

@davidmurdoch davidmurdoch commented Aug 20, 2024

This PR removes load-*.js helpers and load scripts using the defer property instead.

This change drastically improves the performance of the extension but greatly reduces perceived performance because the browser won't display the popup until the DOMContentLoaded event.

But improve perceived performance is mostly regained by initially loading an asset-less HTML file, popup-init.html, that then redirects to the slower (but much faster than before this PR) popup.html.

This was initially authored by @Gudahtt, I've just updated and optimized it to work with the both build systems.

One change I did not make was moving scripts to the head. I don't think putting the scripts in the head does anything in our case1 other than potentially require that we wait for DOMContentLoaded before querying for the app container.

Note: In Firefox we continue to use popup.html. Firefox is very slow to render the popup-init.html redirect, and it renders the page only partially anyway, making the UX feel very janky. It also doesn't delay opening the popup until DOMContentLoaded, like Chrome does, so the issue popup-init.html solves doesn't do anything anyway.


Here is side-by-side video comparison of develop vs popup-defer-scripts.

This video displays the elapsed time from clicking the MetaMask Fox to Lock Screen render.

The end of the video is a frame-by-frame comparison of the new "jank" this PR introduces. The develop branch renders the fox immediately, whereas the popup-defer-scripts branch renders an empty page for about 15 milliseconds.

These stats aren't representative of real world performance, but are intended to illustrate relative performance and perceived performance.

Both builds were created by running yarn build dist.

develop-vs-propup-defer-scripts.mp4

Manual Testing

  1. build with yarn dist
  2. install into your browser and go through onboarding
  3. open MetaMask
  4. Marvel at how much faster it is

Closes #25721

Footnotes

  1. our HTML files are very tiny, and thus will be loaded all in one go, we don't have to worry about packets being lost and retransmitted over the network, delaying the browser's preload scanner.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Copy link

codecov bot commented Aug 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.11%. Comparing base (d3541a3) to head (22281d7).
Report is 72 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #26555      +/-   ##
===========================================
+ Coverage    69.96%   70.11%   +0.15%     
===========================================
  Files         1405     1412       +7     
  Lines        48996    49246     +250     
  Branches     13697    13769      +72     
===========================================
+ Hits         34280    34527     +247     
- Misses       14716    14719       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot
Copy link
Collaborator

Builds ready [4d2b359]
Page Load Metrics (1655 ± 61 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint23022061520449215
domContentLoaded14652003163912058
load15042051165512861
domInteractive126537199
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@davidmurdoch davidmurdoch marked this pull request as ready for review August 20, 2024 22:11
@davidmurdoch davidmurdoch requested review from kumavis and a team as code owners August 20, 2024 22:11
davidmurdoch and others added 3 commits August 20, 2024 18:20
This change drastically improves the performance of the extension but greatly reduces perceived performance because the browser won't display the popup until the DOMContentLoaded event.

A work around for the reduction in perceived performance is in a follow up PR.

Co-authored-by: Mark Stacey <[email protected]>
…s HTML file, `popup-init.html`, that then redirects to the slower `popup.html`

Co-authored-by: Mark Stacey <[email protected]>
@metamaskbot
Copy link
Collaborator

Builds ready [fcf6a91]
Page Load Metrics (1629 ± 52 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15322086163813062
domContentLoaded15131910161110551
load15321939162910852
domInteractive13185353617
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@davidmurdoch davidmurdoch changed the title perf: use an interstitial page to load popup.html; load scripts use defered script tags perf: use an interstitial page to load popup.html; load scripts using defered script tags Aug 20, 2024
@davidmurdoch davidmurdoch added the DO-NOT-MERGE Pull requests that should not be merged label Aug 20, 2024
@HowardBraham HowardBraham added the team-tiger Tiger team (for tech debt reduction + performance improvements) label Aug 21, 2024
@davidmurdoch davidmurdoch added the area-performance Issues relating to slowness of app, cpu usage, and/or blank screens. label Aug 21, 2024
HowardBraham
HowardBraham previously approved these changes Aug 23, 2024
matthewwalsh0
matthewwalsh0 previously approved these changes Aug 23, 2024
itsyoboieltr
itsyoboieltr previously approved these changes Aug 26, 2024
Firefox is very slow to render the `popup-init.html` redirect, and it renders the page only partially anyway, making the UX feel very janky. It also doesn't delay opening the popup until `DOMContentLoaded`, like chrome does, so the issue `popup-init.html` solves doesn't do anything anyway.
Copy link

sonarcloud bot commented Aug 27, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [22281d7]
Page Load Metrics (2053 ± 149 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint23429241694759364
domContentLoaded166129072034308148
load167129262053310149
domInteractive13160554019
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@davidmurdoch davidmurdoch merged commit 82c3634 into develop Aug 28, 2024
83 of 84 checks passed
@davidmurdoch davidmurdoch deleted the popup-defer-scripts branch August 28, 2024 15:07
@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2024
@metamaskbot metamaskbot added the release-12.5.0 Issue or pull request that will be included in release 12.5.0 label Aug 28, 2024
@HowardBraham HowardBraham removed the DO-NOT-MERGE Pull requests that should not be merged label Aug 28, 2024
@Gudahtt Gudahtt restored the popup-defer-scripts branch September 3, 2024 14:15
@metamaskbot metamaskbot added release-12.2.0 Issue or pull request that will be included in release 12.2.0 and removed release-12.5.0 Issue or pull request that will be included in release 12.5.0 labels Sep 3, 2024
@metamaskbot
Copy link
Collaborator

Missing release label release-12.2.0 on PR. Adding release label release-12.2.0 on PR and removing other release labels(release-12.5.0), as PR was cherry-picked in branch 12.2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-performance Issues relating to slowness of app, cpu usage, and/or blank screens. release-12.2.0 Issue or pull request that will be included in release 12.2.0 team-extension-platform team-tiger Tiger team (for tech debt reduction + performance improvements)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Optimize extension UI script loading
5 participants