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: ensure setupLocale doesn't fetch _locales/en/messages.json twice #26553

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

davidmurdoch
Copy link
Contributor

@davidmurdoch davidmurdoch commented Aug 20, 2024

We always load the english version of messages.json, but we also always load the user's locale's messages.json. These can be the same thing but our locale loader didn't take that into consideration. This PR updates the function to only load the user's local if it differs from our default locale, otherwise it just uses the same messages.json between the two.

Our locale function has a side effect: it loads locale-related Internationalization features as well. So this PR also updates those side-effects in a similar manner to avoid doing the work twice.

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.

@metamaskbot
Copy link
Collaborator

Builds ready [76c903e]
Page Load Metrics (87 ± 22 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint723391175727
domContentLoaded39255844622
load46256874522
domInteractive97029178
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 77 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

codecov bot commented Aug 20, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 70.01%. Comparing base (d3541a3) to head (ba6741c).
Report is 15 commits behind head on develop.

Files Patch % Lines
shared/lib/error-utils.js 83.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #26553      +/-   ##
===========================================
+ Coverage    69.96%   70.01%   +0.05%     
===========================================
  Files         1405     1405              
  Lines        48996    49049      +53     
  Branches     13697    13714      +17     
===========================================
+ Hits         34280    34341      +61     
+ Misses       14716    14708       -8     

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

Copy link

sonarcloud bot commented Aug 20, 2024

Comment on lines +8 to +28
const enRelativeTime = loadRelativeTimeFormatLocaleData(defaultLocale);
const enLocale = fetchLocale(defaultLocale);

await loadRelativeTimeFormatLocaleData('en');
if (currentLocale) {
await loadRelativeTimeFormatLocaleData(currentLocale);
const promises = [enRelativeTime, enLocale];
if (currentLocale === defaultLocale) {
// enLocaleMessages and currentLocaleMessages are the same; reuse enLocale
promises.push(enLocale); // currentLocaleMessages
} else if (currentLocale) {
// currentLocale does not match enLocaleMessages
promises.push(fetchLocale(currentLocale)); // currentLocaleMessages
promises.push(loadRelativeTimeFormatLocaleData(currentLocale));
} else {
// currentLocale is not set
promises.push(Promise.resolve({})); // currentLocaleMessages
}

const [, enLocaleMessages, currentLocaleMessages] = await Promise.all(
promises,
);
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 is really two changes:

  1. don't fetch the "en" locale twice
  2. if we have to fetch multiple locales, do them at the same time.

@metamaskbot
Copy link
Collaborator

Builds ready [ba6741c]
Page Load Metrics (75 ± 6 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint77129105168
domContentLoaded5410673126
load6010675126
domInteractive13482573
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 77 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@HowardBraham HowardBraham added the team-tiger Tiger team (for tech debt reduction + performance improvements) label Aug 21, 2024
@davidmurdoch davidmurdoch marked this pull request as ready for review September 18, 2024 21:53
@davidmurdoch davidmurdoch requested a review from a team as a code owner September 18, 2024 21:53
@metamaskbot
Copy link
Collaborator

Builds ready [5982850]
Page Load Metrics (1993 ± 128 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint23927301730665319
domContentLoaded166525101953227109
load167527811993268128
domInteractive165635105
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 77 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link

sonarcloud bot commented Oct 11, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [5a18b3a]
Page Load Metrics (2047 ± 57 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint43222411955369177
domContentLoaded17222178200311656
load18062243204711957
domInteractive1792512211
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 68 Bytes (0.00%)
  • ui: 77 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [b49a9a4]
Page Load Metrics (1931 ± 104 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint168924771930216104
domContentLoaded167524561905212102
load168324811931217104
domInteractive18188523417
backgroundConnect979382211
firstReactRender603111135024
getState471212010
initialActions01000
loadScripts11761882140717885
setupStore55612136
uiStartup188432492165314151
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 77 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@davidmurdoch davidmurdoch added this pull request to the merge queue Nov 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 7, 2024
@HowardBraham HowardBraham added this pull request to the merge queue Nov 7, 2024
Merged via the queue into develop with commit 2484e86 Nov 7, 2024
76 checks passed
@HowardBraham HowardBraham deleted the optimize-setuplocale branch November 7, 2024 18:22
@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2024
@metamaskbot metamaskbot added the release-12.8.0 Issue or pull request that will be included in release 12.8.0 label Nov 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.8.0 Issue or pull request that will be included in release 12.8.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