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: optimize fonts by using woff2 instead of ttf #26554

Merged
merged 6 commits into from
Nov 19, 2024
Merged

Conversation

davidmurdoch
Copy link
Contributor

@davidmurdoch davidmurdoch commented Aug 20, 2024

Reason for change: woff2 is has been supported by Firefox and Chrome since circa 2015, so it's safe to use. It's designed specifically for use on the web. It is a smaller format than an equivalent ttf (which we were using prior to this PR).

This PR isn't substantial. On my machine it shaves only 8 milliseconds off of our popup's load time (from ~60.5ms to 52.5ms - using #26555 as the baseline).

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

socket-security bot commented Aug 20, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/postcss-discard-font-face@3.0.0 Transitive: environment, filesystem +5 679 kB beneb

View full report↗︎

@davidmurdoch davidmurdoch force-pushed the optimize-fonts branch 3 times, most recently from 3ffb029 to 8fe8185 Compare August 20, 2024 22:51
@davidmurdoch davidmurdoch added the DO-NOT-MERGE Pull requests that should not be merged label Aug 20, 2024
// can test this by uncommenting it, running with --zip, and then unzipping
// the resulting zip file. If it is still broken the unzip operation will
// show an error.
// '.ttf',
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 don't have any ttf files anymore, so this comment about uncommenting is no longer true, so i've removed it.

attributes: { as: 'font', crossorigin: true },
// preload our own fonts, as other fonts use fallback formats we don't
// want to preload
test: /fonts\/\.(?:woff2)$/u,
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 adds preload link tags to home.html, popup.html, and notification.html. Neat!

@@ -323,7 +333,7 @@ const config = {
},
// images, fonts, wasm, etc.
{
test: /\.(?:png|jpe?g|ico|webp|svg|gif|ttf|eot|woff2?|wasm)$/u,
test: /\.(?:png|jpe?g|ico|webp|svg|gif|woff2|wasm)$/u,
Copy link
Contributor Author

@davidmurdoch davidmurdoch Aug 20, 2024

Choose a reason for hiding this comment

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

This change wasn't really necessary, as the removed font formats (ttf and eot) would still be parsed and handled by webpack, but they'll just end up in a different place with a weird name. I still like getting them out of our logic here though, just because its slightly simpler to read.

@@ -0,0 +1,68 @@
declare module 'postcss-discard-font-face' {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh, this package didn't have types so I made them myself.

@HowardBraham HowardBraham added the team-tiger Tiger team (for tech debt reduction + performance improvements) label Aug 21, 2024
Copy link

codecov bot commented Aug 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.01%. Comparing base (c85cf5b) to head (3986be9).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #26554   +/-   ##
========================================
  Coverage    70.01%   70.01%           
========================================
  Files         1410     1410           
  Lines        49130    49130           
  Branches     13739    13739           
========================================
  Hits         34398    34398           
  Misses       14732    14732           

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

@metamaskbot
Copy link
Collaborator

Builds ready [8fe8185]
Page Load Metrics (70 ± 6 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7113697178
domContentLoaded488864126
load559470126
domInteractive185426105
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@davidmurdoch davidmurdoch added the area-performance Issues relating to slowness of app, cpu usage, and/or blank screens. label Aug 21, 2024
Copy link

sonarcloud bot commented Aug 21, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [3986be9]
Page Load Metrics (74 ± 8 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6013197189
domContentLoaded4510871178
load4610874168
domInteractive95825136
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 21, 2024 16:44
@davidmurdoch davidmurdoch requested review from a team and kumavis as code owners August 21, 2024 16:44
@georgewrmarshall
Copy link
Contributor

Great update! Any way we can see the performance improvements from these changes?

@davidmurdoch davidmurdoch requested a review from a team as a code owner September 18, 2024 21:54
Copy link

sonarcloud bot commented Sep 18, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [673091f]
Page Load Metrics (1804 ± 119 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint29824851746415199
domContentLoaded149424091779236113
load150224961804248119
domInteractive137236199
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

socket-security bot commented Nov 8, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Medium CVE npm/postcss@5.2.18 ⚠︎

View full report↗︎

Next steps

What is a medium CVE?

Contains a medium severity Common Vulnerability and Exposure (CVE).

Remove or replace dependencies that include known medium severity CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore npm/postcss@5.2.18

}

@font-face {
font-family: 'Euclid Circular B';
font-style: normal;
font-weight: 500;
src: url('#{$font-path}/Euclid/EuclidCircularB-Medium.ttf') format('truetype');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The newest font package has a EuclidCircularB-Medium-WebS.woff2 and a EuclidCircularB-Medium-WebXL.woff2. It doesn't have a EuclidCircularB-Medium.woff2, so I just went with the WebXL version because all of our other fonts also use that version.

@davidmurdoch davidmurdoch removed the DO-NOT-MERGE Pull requests that should not be merged label Nov 8, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [88519e9]
Page Load Metrics (1820 ± 51 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint16642131182310550
domContentLoaded16472108178510048
load16682133182010651
domInteractive247740147
backgroundConnect8101382813
firstReactRender482801075225
getState46117189
initialActions00000
loadScripts1185158413188943
setupStore586152110
uiStartup18512468204416077
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@georgewrmarshall georgewrmarshall left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

  • Check storybook font attributes ✅
  • Checked extension ran locally as expected ✅
Screenshot 2024-11-15 at 8 48 03 AM

@davidmurdoch davidmurdoch added this pull request to the merge queue Nov 19, 2024
Merged via the queue into develop with commit 39528b0 Nov 19, 2024
76 of 77 checks passed
@davidmurdoch davidmurdoch deleted the optimize-fonts branch November 19, 2024 18:10
@github-actions github-actions bot locked and limited conversation to collaborators Nov 19, 2024
@metamaskbot metamaskbot added the release-12.9.0 Issue or pull request that will be included in release 12.9.0 label Nov 19, 2024
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.9.0 Issue or pull request that will be included in release 12.9.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.

5 participants