near / near-wallet

Web wallet for NEAR Protocol which stores keys in browser's localStorage
https://wallet.near.org
MIT License
220 stars 176 forks source link

Excessive # of identical JSON RPC requests being made during screen render #1574

Open MaximusHaximus opened 3 years ago

MaximusHaximus commented 3 years ago

Problem When loading the UI and switching pages, an excessive number of completely identical/redundant RPC requests are being made.

For example, loading the Account page results in 15 identical requests with payload shape: image on my mainnet account

17 identical requests with payload shape: image are made on my testnet account

When sorting the requests by payload size (like sizes are the result of identical requests being made with identical responses returned), check out the waterfall for page load: image

Expected Behavior Ideally the app would only load a logical piece of data once during page initialization/screen loads, rather than fetching the same data multiple times. Although the account detail page is the worst offender, there are duplicate requests being made for a couple of other JSONRPC calls also (4x calls to query access keys for my account, and 5x queries for EXPERIMENTAL_protocol_config) for the same logical data.

Steps to reproduce

  1. Open wallet with an account linked
  2. Open network devtools panel and record network traffic
  3. Switch to 'Account' screen
  4. Observe redundant and excessive network requests being made
MaximusHaximus commented 3 years ago

If this is just the result of a lot of different components requesting the same logical data in series, then it might be a good solution to implement data loader to handle coalescing/caching (https://github.com/graphql/dataloader)