-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Integrate StorageService for large controller data #22943
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
base: main
Are you sure you want to change the base?
Conversation
Add StorageService integration to enable controllers to offload large data
from Redux state to persistent storage.
**Problem**:
- 10.79 MB Engine state with 92% in 2 controllers
- Slow app startup parsing large state
- High memory usage from rarely-accessed data
**Solution**:
StorageService integration with FilesystemStorage adapter:
- Platform-agnostic service via messenger actions
- Event system for reactive patterns
- FilesystemStorage adapter for mobile persistence
- Namespace isolation (storageService:{namespace}:{key})
**Implementation**:
- StorageService registered in Engine
- FilesystemStorage adapter with namespace filtering
- Messenger delegation configured
- Service available for all controllers
- Uses STORAGE_KEY_PREFIX constant
**Impact** (when controllers migrate):
- 92% state reduction potential (10.79 MB → 0.85 MB)
- SnapController: 6.09 MB sourceCode candidate
- TokenListController: 4.09 MB cache candidate
**Files**:
- storage-service-init.ts: FilesystemStorage adapter
- storage-service-messenger.ts: Messenger factory
- Engine types/messengers: Registration
- Tests: Integration verified
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsSummaryThis PR introduces a new StorageService to the core Engine infrastructure of MetaMask Mobile. This is a significant architectural change that adds persistent storage capabilities for controller data. Changes Made
Risk Assessment - HIGHWhy High Risk:
Potential Impact Areas:
Test Tag Selection RationaleSelected Tags:
Why Not Other Tags:
Confidence: 85%Why High Confidence:
Why Not 100%:
|
Integrate StorageService for Large Controller Data
Description
Integrates
@metamask/storage-serviceto enable controllers to offload large, infrequently-accessed data from Redux state to persistent storage.Problem
State bloat impacting mobile performance:
Root cause: Controllers store large data (snap source code, token caches) in Redux state instead of on disk.
Solution
Add StorageService integration - Controllers can now store large data via messenger:
What's Included
StorageService Integration:
storage-service-init.ts- FilesystemStorage adapter for mobilestorage-service-messenger.ts- Messenger factoryFilesystemStorage Adapter (mobile-specific):
StorageAdapterinterfacegetAllKeys,clear)STORAGE_KEY_PREFIXconstant (storageService:)Impact
Immediate (infrastructure ready):
When controllers migrate (separate PRs):
Architecture
Platform-agnostic service:
Key format:
storageService:{namespace}:{key}Example:
storageService:SnapController:snap-id:sourceCodeTesting
Test coverage:
Follow-up Work
Controller migrations (separate PRs):
Each migration requires:
Related
@metamask/storage-service@^1.0.0(from core)Checklist
Notes
This PR adds infrastructure only - No immediate user-facing changes.
Performance improvements come when controllers are migrated to use StorageService (separate PRs for each controller).
Why FilesystemStorage? Optimized for large files (multi-MB). MMKV is better for small, frequently-accessed data (< 1 MB).