-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 redux state patches #26738
Conversation
Add patch store.
Support raw state update. Fix decrypt test.
Increase driver timeout.
Builds ready [1e27752]
Page Load Metrics (1675 ± 82 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [3c4e8ae]
Page Load Metrics (1767 ± 80 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #26738 +/- ##
===========================================
- Coverage 70.02% 69.99% -0.04%
===========================================
Files 1443 1445 +2
Lines 50164 50226 +62
Branches 14039 14045 +6
===========================================
+ Hits 35126 35151 +25
- Misses 15038 15075 +37 ☔ View full report in Codecov by Sentry. |
Builds ready [b5f22e8]
Page Load Metrics (1741 ± 99 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [b5968fe]
Page Load Metrics (1700 ± 74 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Quality Gate passedIssues Measures |
Builds ready [54bbdf5]
Page Load Metrics (1848 ± 148 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a minor comment but it is looking great 🚀 🔥
* Intentionally not using immer as a temporary measure to avoid | ||
* freezing the resulting state and requiring further fixes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was just thinking about why are we not using immer for applying the patches... I guess this explains it 😅
Quality Gate passedIssues Measures |
Builds ready [86ab71d]
Page Load Metrics (1935 ± 116 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Missing release label release-12.5.0 on PR. Adding release label release-12.5.0 on PR and removing other release labels(release-12.6.0), as PR was added to branch 12.5.0 when release was cut. |
Description
Currently, the background page / service worker subscribes to state changes from every controller and on each state change (debounced to 200ms), sends the full flattened state to the UI where it is stored in the
metamask
duck.The primary drawback of this is that Redux and React default to shallow equality comparisons meaning any object and array state is always detected as new, resulting in frequent unnecessary renders unless deep equality is explicitly used through mechanisms such as
createDeepEqualSelector
.This PR aims to resolve this by instead sending state patches to the UI, and only for the top level state properties that no longer have shallow equality. These patches are then applied to the MetaMask duck in the UI, meaning it is now incrementally updated and any object and array references are only updated when the data itself has changed.
This logic is encapsulated within the new
PatchStore
class, with an alternate instance being created for each UI connection.The patches are currently intentionally generated and applied without
immer
given this has the side effect of freezing the associated state, which triggers multiple errors due to pre-existing instances of direct state mutation in the background and UI code.Related issues
Fixes: #2987
Manual testing steps
No functional changes, but high level sanity checks would be beneficial given risk.
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist