feat: integrate token list controller storage service#24019
feat: integrate token list controller storage service#24019sahar-fehri merged 23 commits intomainfrom
Conversation
|
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. |
| + if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); | ||
| + return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; | ||
| +}; | ||
| +var _TokenListController_instances, _a, _TokenListController_mutex, _TokenListController_storageKeyPrefix, _TokenListController_getChainStorageKey, _TokenListController_intervalId, _TokenListController_intervalDelay, _TokenListController_cacheRefreshThreshold, _TokenListController_chainId, _TokenListController_abortController, _TokenListController_loadCacheFromStorage, _TokenListController_saveChainCacheToStorage, _TokenListController_migrateStateToStorage, _TokenListController_onNetworkControllerStateChange, _TokenListController_stopPolling, _TokenListController_startDeprecatedPolling; |
There was a problem hiding this comment.
patch file to be removed after release, this is just for testing
| async getAllKeys(namespace: string): Promise<string[]> { | ||
| // eslint-disable-next-line no-console | ||
| console.warn(`[StorageService DEBUG] getAllKeys called: ${namespace}`); | ||
| const startTime = performance.now(); |
There was a problem hiding this comment.
perf logs to be cleaned up
app/store/persistConfig/index.ts
Outdated
| const totalDuration = performance.now() - startTime; | ||
|
|
||
| // Log performance for TokenListController specifically | ||
| if (controllerName === 'TokenListController') { |
There was a problem hiding this comment.
Change to be reverted; only for testing
| return allKeys | ||
| const filteredKeys = allKeys | ||
| .filter((key) => key.startsWith(prefix)) | ||
| .map((key) => key.slice(prefix.length)); |
There was a problem hiding this comment.
Filter to only keys that belong to the requested namespace
.yarn/patches/@metamask-assets-controllers-npm-94.0.0-0b6df6cf06.patch
Outdated
Show resolved
Hide resolved
dfa8049 to
070448e
Compare
.yarn/patches/@metamask-assets-controllers-npm-94.1.0-481519c877.patch
Outdated
Show resolved
Hide resolved
.yarn/patches/@metamask-assets-controllers-npm-94.1.0-481519c877.patch
Outdated
Show resolved
Hide resolved
.yarn/patches/@metamask-assets-controllers-npm-94.1.0-481519c877.patch
Outdated
Show resolved
Hide resolved
.yarn/patches/@metamask-assets-controllers-npm-94.1.0-481519c877.patch
Outdated
Show resolved
Hide resolved
.yarn/patches/@metamask-assets-controllers-npm-94.1.0-481519c877.patch
Outdated
Show resolved
Hide resolved
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24019 +/- ##
==========================================
+ Coverage 79.96% 80.06% +0.09%
==========================================
Files 4257 4279 +22
Lines 109331 110175 +844
Branches 22889 23103 +214
==========================================
+ Hits 87429 88214 +785
+ Misses 15835 15834 -1
- Partials 6067 6127 +60 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
758ee8f
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Selected tags rationale:
This is marked as HIGH risk because:
Performance Test Selection: |
|
|
Missing release label release-7.64.0 on PR. Adding release label release-7.64.0 on PR and removing other release labels(release-7.65.0), as PR was added to branch 7.64.0 when release was cut. |
|
No release label on PR. Adding release label release-7.64.0 on PR, as PR was added to branch 7.64.0 when release was cut. |



Description
Do not merge until this is released MetaMask/core#7413
Performance Comparison: Per-Chain Token Cache Storage
This PR implements per-chain file storage for
tokensChainsCacheinTokenListController, replacing the single-file approach. Each chain's token list is now stored in a separate file, reducing write amplification during incremental updates.📊 Complete Performance Comparison
Cold Restart
Main is ~44ms faster on cold restart (single file read vs parallel reads + getAllKeys overhead)
Onboarding
This PR writes 57% less data and is 3x faster
Add New Chain (Monad)
This PR is 121x smaller and 197x faster!
Summary
📋 Captured Logs
This PR - Cold Restart
This PR - Onboarding
This PR - Add New Chain (Monad)
Main Branch - Cold Restart
Main Branch - Onboarding
Main Branch - Add New Chain (Monad)
🔧 Performance Logging Code (Main Branch)
The following code was added to
app/store/persistConfig/index.tsto capture performance metrics:Read Performance Logging (getAllPersistedState)
Write Performance Logging (createPersistController)
🔧 Performance Logging Code (This PR)
The following code was added to
app/core/Engine/controllers/storage-service-init.tsto capture performance metrics for the per-chain storage:getItem - Read Performance Logging
setItem - Write Performance Logging
getAllKeys - Key Enumeration Logging
Changelog
CHANGELOG entry: integrates per chain file save for tokenListController.
Related issues
Related: MetaMask/core#7413
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Introduces per-chain StorageService-backed persistence for
TokenListControllerand migrates existing cache data.114to moveTokenListController.tokensChainsCachefrom Redux state to per-chain filesystem keys (storageService:TokenListController:tokensChainsCache:{chainId}), avoids overwrites, handles errors, and clears in-state cache; includes comprehensive testsTokenListControllermessenger to allowStorageService:getAllKeys|getItem|setItem|removeItemtoken-list-controller-initto pass persisted state, subscribe to network changes, and callcontroller.initialize(); adds tests mocking controller and verifying initialize@metamask/assets-controllersto^98.0.0and registers migration inmigrations/index.tsWritten by Cursor Bugbot for commit 385b6a3. This will update automatically on new commits. Configure here.