Skip to content

fix: Improve performance of getSelectedAccount#24745

Merged
darkwing merged 4 commits intodevelopfrom
getSelectedAccount-perf
May 28, 2024
Merged

fix: Improve performance of getSelectedAccount#24745
darkwing merged 4 commits intodevelopfrom
getSelectedAccount-perf

Conversation

@darkwing
Copy link
Copy Markdown
Contributor

@darkwing darkwing commented May 23, 2024

Description

When exploring the extension performance, I spotted that the getSelectedAccount selector that was introduced for Multichain was returning a new object, thus the new object reference causing unnecessary re-renders of components using it. The top-most UI component, routes.container.js, was using this selector, which could cause a significant UI perf impact. This PR memoizes that result, ensuring routes.container.js doesn't make unnecessary re-renders.

Open in GitHub Codespaces

Related issues

Fixes: N/A

Manual testing steps

BEFORE CHECKING OUT THIS PR, open routes.component.js and add the following in componentDidUpdate:

console.log('[routes.component.js] componentDidUpdate ---------------------------');
    const keyz = Object.keys(this.props);
    keyz.forEach((key) => {
      if (this.props[key] !== prevProps[key]) {
        console.warn('[prop value inequality]: ', key, this.props[key], prevProps[key]);
      }
    });

See that the account property displays in this list. This means an unnecessary update is happening.

After checking out this PR, that key should not display in the warning.

Screenshots/Recordings

Before

After

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@darkwing darkwing requested a review from a team as a code owner May 23, 2024 14:54
@darkwing darkwing added team-core-extension-ux Core Extension UX team needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. labels May 23, 2024
@github-actions
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

Builds ready [2f793d5]
Page Load Metrics (871 ± 531 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint68172912713
domContentLoaded9181231
load5425828711105531
domInteractive9181231
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 36 Bytes (0.00%)

@codecov
Copy link
Copy Markdown

codecov bot commented May 24, 2024

Codecov Report

Attention: Patch coverage is 44.44444% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 66.01%. Comparing base (9b06ab4) to head (5ab1dae).

Files Patch % Lines
ui/selectors/selectors.js 44.44% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #24745   +/-   ##
========================================
  Coverage    66.01%   66.01%           
========================================
  Files         1348     1348           
  Lines        52505    52507    +2     
  Branches     13498    13497    -1     
========================================
+ Hits         34656    34658    +2     
  Misses       17849    17849           

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

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [8c73ad7]
Page Load Metrics (1343 ± 604 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint782001232914
domContentLoaded10411784
load63312913431258604
domInteractive10411784
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 36 Bytes (0.00%)

@darkwing darkwing merged commit f9c5853 into develop May 28, 2024
@darkwing darkwing deleted the getSelectedAccount-perf branch May 28, 2024 17:04
@github-actions github-actions bot locked and limited conversation to collaborators May 28, 2024
@gauthierpetetin gauthierpetetin added the release-12.0.0 Issue or pull request that will be included in release 12.0.0 label Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-assets-ux-review A shared label between the Assets and UX team to flag PRs ready for consolidated team review. release-12.0.0 Issue or pull request that will be included in release 12.0.0 team-core-extension-ux Core Extension UX team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants