perf(earn): use memoized selectPendingApprovalIds instead of isEqual …#33181
Conversation
…in useMusdConversion Replaces the deep-equality-guarded selectPendingApprovals subscription in useMusdConversion with a local createSelector-based selectPendingApprovalIds projection selector. This avoids running lodash isEqual over the entire pending approvals map on every Redux dispatch when the hook only consumes the set of approval IDs. Kept the new selector local to useMusdConversion.ts (rather than adding it to approvalController.ts) to minimize surface area, since this feature is currently flagged off and approvalController.ts is owned by another team. Fixes #31337
…usd-conversion-pending-approval-ids-selector
PR template — items to address before "Ready for review"Warnings — informational, address before merging:
See docs/readme/ready-for-review.md for the full Definition of Ready for Review. |
119e918 to
40dd16f
Compare
…usd-conversion-pending-approval-ids-selector
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Since:
No E2E smoke tags are warranted. No performance tags are warranted either — this is a micro-optimization to selector memoization that would not measurably affect any of the performance test scenarios. Performance Test Selection: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #33181 +/- ##
==========================================
+ Coverage 84.37% 84.39% +0.01%
==========================================
Files 6127 6132 +5
Lines 163530 163730 +200
Branches 39887 39925 +38
==========================================
+ Hits 137974 138175 +201
+ Misses 16050 16044 -6
- Partials 9506 9511 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|



Replaces the deep-equality-guarded selectPendingApprovals subscription in useMusdConversion with a new createSelector-based selectPendingApprovalIds projection selector. This avoids running lodash isEqual over the entire pending approvals map on every Redux dispatch when the hook only consumes the set of approval IDs.
Description
useMusdConversion subscribed to selectPendingApprovals (the raw pending-approvals map) with a lodash.isEqual comparator, then derived Object.keys(pendingApprovals ?? {}) via useMemo. Since the hook only ever consumes the approval IDs, the deep comparison of the entire approvals map on every Redux dispatch was unnecessary overhead — a band-aid for a missing memoized projection selector.
Changelog
CHANGELOG entry: null
Related issues
Fixes: #31337
Manual testing steps
Screenshots/Recordings
Before
N/A
After
N/A
Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist
Note
Low Risk
Behavior-preserving selector refactor in a feature-flagged Earn hook with no auth, payment, or shared controller API changes.
Overview
useMusdConversionno longer subscribes to the full pending-approvals map withlodash.isEqual. It now uses a localcreateSelectorprojection,selectPendingApprovalIds, that derivesObject.keysfromselectPendingApprovalssouseSelectorcan use default reference equality and skip deep compares on every Redux dispatch when only approval IDs matter.Unit tests cover key extraction, empty state, and stable vs. new array references when the underlying map is unchanged or updated. The selector stays in the hook file rather than
approvalControllerselectors to keep the change scoped to Earn/mUSD.Reviewed by Cursor Bugbot for commit f044975. Bugbot is set up for automated code reviews on this repo. Configure here.