Skip to content

perf: Speed up the creation of the token list for Predict withdraw#27735

Merged
dan437 merged 4 commits into
mainfrom
withdraw-perf-update-2
Mar 20, 2026
Merged

perf: Speed up the creation of the token list for Predict withdraw#27735
dan437 merged 4 commits into
mainfrom
withdraw-perf-update-2

Conversation

@dan437

@dan437 dan437 commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Description

This speeds up the withdraw token-selection path by moving the allowlist filter earlier in the pipeline.

Before this change, withdraw flows loaded the full token catalog, built AssetTypes for all matching catalog entries, sorted the full result, and only then filtered down to the small allowlisted set we actually care about. This change adds a tokenFilter hook parameter so useAccountTokens can skip irrelevant catalog entries before building them, and useWithdrawTokenFilter passes the withdraw allowlist down to that lower-level loop.

It also keeps the existing post-filter in place for correctness, so allowlisted tokens already owned by the user and native-token address mapping still work as before.

Local dev measurements while opening Predict Withdraw:

Metric Before After
useAccountTokens 954-1,143ms 41-48ms
Catalog tokens built 18,524 0
Total tokens sorted 18,618 15

This brings the measured token-loading path from roughly ~1.05s down to ~44ms (~24x faster).

Changelog

CHANGELOG entry: Improved performance when loading Predict withdraw token selection

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/CONF-1054

Manual testing steps

  1. Open Predict Withdraw, it will load much faster now

Note

Medium Risk
Medium risk because it changes how withdraw token lists are constructed and filtered, which could inadvertently hide valid tokens if chainId/address normalization or assetId handling is wrong. Scope is limited to token-selection hooks and is covered by updated/added unit tests.

Overview
Speeds up Predict Withdraw token selection by pushing the withdraw allowlist filter down into token collection, avoiding building/sorting the full token catalog before narrowing to allowlisted entries.

This introduces an optional tokenFilter(chainId, address) plumbed from useWithdrawTokenFilteruseSendTokensuseAccountTokens, and replaces the previous post-filtering in useWithdrawTokenFilter with a precomputed allowlist lookup that also maps zero-address entries to chain-specific native token addresses.

Tests are updated to assert useSendTokens is called with the new filtering options and to validate tokenFilter behavior (case-insensitive matching, chain gating, and native-token mapping), plus new useAccountTokens coverage ensuring both owned assets and catalog token building respect tokenFilter.

Written by Cursor Bugbot for commit b8e1cc7. This will update automatically on new commits. Configure here.

@dan437 dan437 requested a review from a team as a code owner March 20, 2026 12:51
@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 metamaskbot added team-confirmations Push issues to confirmations team INVALID-PR-TEMPLATE PR's body doesn't match template labels Mar 20, 2026
@github-actions github-actions Bot added size-M risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 20, 2026
Comment thread app/components/Views/confirmations/hooks/send/useAccountTokens.ts
@dan437 dan437 force-pushed the withdraw-perf-update-2 branch from 3abe8c1 to 1cc14e8 Compare March 20, 2026 13:54
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 20, 2026
@dan437 dan437 force-pushed the withdraw-perf-update-2 branch from 1cc14e8 to c146b59 Compare March 20, 2026 14:38
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 20, 2026
@dan437 dan437 enabled auto-merge March 20, 2026 15:31
@dan437 dan437 dismissed matthewwalsh0’s stale review March 20, 2026 15:54

Already resolved.

dan437 added 4 commits March 20, 2026 16:54
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
Signed-off-by: dan437 <80175477+dan437@users.noreply.github.com>
@dan437 dan437 force-pushed the withdraw-perf-update-2 branch from c146b59 to b8e1cc7 Compare March 20, 2026 15:55
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@dan437 dan437 added the skip-e2e skip E2E test jobs label Mar 20, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeConfirmations, SmokePredictions, SmokeWalletPlatform
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes refactor token filtering logic in the confirmations hooks layer:

  1. useAccountTokens.ts - Added optional tokenFilter parameter that filters tokens during asset building (both owned assets and catalog tokens). This is used in send flows and pay flows.

  2. useSendTokens.ts - Passes the new tokenFilter parameter through to useAccountTokens. Used in send asset selection and withdraw token filtering.

  3. useWithdrawTokenFilter.ts - Refactored to build an O(1) Map/Set lookup and pass it as tokenFilter to useSendTokens instead of post-filtering results. This hook is specifically for predictWithdraw transaction type (Predictions feature).

SmokeConfirmations: Directly required - useSendTokens and useAccountTokens are core to the send flow token selection in confirmations. The asset.tsx component in send confirmations uses useSendTokens. Any regression in token filtering could break send flows.

SmokePredictions: The useWithdrawTokenFilter hook is specifically tied to TransactionType.predictWithdraw - the Predictions withdraw flow. The refactored logic (moving filtering upstream via tokenFilter callback) needs validation that the correct tokens are still shown in the Predictions withdraw UI.

SmokeWalletPlatform: Required per SmokePredictions tag description - Predictions is a section inside the Trending tab (SmokeWalletPlatform), so changes to Predictions flows affect Trending.

The changes are a refactor with the same intended behavior but different implementation. Risk is medium because incorrect token filtering could silently show wrong tokens or no tokens in send/withdraw flows.

Performance Test Selection:
The changes are a performance optimization (O(1) Map/Set lookups replacing O(n) array searches in allowlist filtering), but they don't affect UI rendering performance, component structure, list rendering, or app startup. The tokenFilter is a pure computation improvement that doesn't warrant performance test execution.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@dan437 dan437 added this pull request to the merge queue Mar 20, 2026
Merged via the queue into main with commit 045a39f Mar 20, 2026
235 of 279 checks passed
@dan437 dan437 deleted the withdraw-perf-update-2 branch March 20, 2026 17:53
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 20, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M skip-e2e skip E2E test jobs team-confirmations Push issues to confirmations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants