Skip to content
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

[Fix] Optimize React Query Storage Usage #1825

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

BrodyHughes
Copy link
Member

@BrodyHughes BrodyHughes commented Jan 29, 2025

Problem

Our chrome.storage.local was experiencing significant bloat, with the react-query storage reaching ~25MB. This caused slow performance and e2e failures. This was primarily due to:

  • Excessive storage of pending queries
  • No throttling of storage updates
  • Lack of proper garbage collection for multi-chain queries
  • Storing and persisting all query states regardless of their usefulness

Changes

  1. Query Client Persistence Configuration

    • Added throttling (2000ms) to prevent rapid storage updates
    • Implemented proper serialization/deserialization
    • Added buster key to help with cache invalidation
    • Reduced maxAge to 1 hour to prevent stale data accumulation
  2. Asset Metadata Query Optimizations

    • Incremented persisterVersion to clear old cached data
    • Added proper error handling to prevent caching failed states
    • Implemented early returns for invalid data to reduce storage
    • Added sensible defaults for query configurations:
      • staleTime: 5 minutes
      • cacheTime: 30 minutes
      • Disabled retries to prevent unnecessary network calls
      • Added enable conditions to prevent unnecessary queries
  3. Storage Layer Improvements

    • Added better error handling and logging
    • Improved type safety for stored values
    • Added debug logging for storage operations

Results

Storage usage for react-query has been reduced from ~25MB to ~2.5MB, a 90% reduction in storage usage.

Testing

  • Verified storage size reduction in chrome.storage.local
  • Confirmed asset metadata queries still function correctly
  • Tested multi-chain query functionality
  • Verified persistence across extension restarts

@BrodyHughes BrodyHughes changed the title add timeouts, cache sizes, and make sure data structures are as expected Optimize React Query Storage Usage Jan 29, 2025
@BrodyHughes BrodyHughes marked this pull request as ready for review January 31, 2025 20:18
@BrodyHughes BrodyHughes changed the title Optimize React Query Storage Usage [Fix] Optimize React Query Storage Usage Jan 31, 2025
@BrodyHughes
Copy link
Member Author

open to feedback on if theres better ways to structure this or if this seems like overkill. there may be things i'm not considering, since i am not super experienced with react-query.

@BrodyHughes BrodyHughes self-assigned this Feb 3, 2025
@BrodyHughes BrodyHughes requested a review from jinchung February 11, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant