1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/app/scripts/controllers
Whymarrh Whitby c7fad8f400
Limit number of transactions passed outside of TransactionController (#9010)
Refs #8572
Refs #8991

This change limits the number of transactions (`txMeta`s) that are passed
outside of the `TransactionController`, resulting in shorter serialization and
deserialization times when state is moved between the background and UI
contexts.

`TransactionController#_updateMemstore`
---------------------------------------

The `currentNetworkTxList` state of the `TransactionController` is used
externally (i.e. outside of the controller) as the canonical source for
the full transaction history. Prior to this change, the method would iterate
the full transaction history and possibly return all of it.

This change limits it to `MAX_MEMSTORE_TX_LIST_SIZE` to make sure that:

1. Calls to `_updateMemstore` are fast(er)
2. Passing `currentNetworkTxList` around is fast(er)

(Shown in #8377, `_updateMemstore`, is called _frequently_ when a transaction
is pending.)

The list is iterated backwards because it is possible that new transactions are
at the end of the list. [1]

Results
-------

In profiles before this change, with ~3k transactions locally,
`PortDuplexStream._onMessage` took up to ~4.5s to complete when the set of
transactions is included. [2]

In profiles after this change, `PortDuplexStream._onMessage` took ~90ms to
complete. [3]

Before vs. after profile screenshots:

![Profile 1][2]
![Profile 2][3]

  [1]:5a3ae85b72/app/scripts/controllers/transactions/tx-state-manager.js (L172-L174)
  [2]:https://user-images.githubusercontent.com/1623628/87613203-36f51d80-c6e7-11ea-89bc-11a1cc2f3b1e.png
  [3]:https://user-images.githubusercontent.com/1623628/87613215-3bb9d180-c6e7-11ea-8d85-aff3acbd0374.png
  [8337]:https://github.com/MetaMask/metamask-extension/issues/8377
  [8572]:https://github.com/MetaMask/metamask-extension/issues/8572
  [8991]:https://github.com/MetaMask/metamask-extension/issues/8991
2020-07-16 17:52:41 -02:30
..
ens Move export defaults statements alongside their objects (#8525) 2020-05-05 19:49:38 -02:30
network Use string network and chain IDs (#8628) 2020-07-08 14:05:09 -07:00
permissions Fix web3_clientVersion method (#8998) 2020-07-15 15:34:10 -03:00
transactions Limit number of transactions passed outside of TransactionController (#9010) 2020-07-16 17:52:41 -02:30
alert.js Use eslint@6.8.0 (#8978) 2020-07-14 12:50:41 -02:30
app-state.js Persist home tab state (#8612) 2020-05-25 16:31:28 -02:30
cached-balances.js Move export defaults statements alongside their objects (#8525) 2020-05-05 19:49:38 -02:30
detect-tokens.js Move export defaults statements alongside their objects (#8525) 2020-05-05 19:49:38 -02:30
incoming-transactions.js Use string network and chain IDs (#8628) 2020-07-08 14:05:09 -07:00
onboarding.js Move export defaults statements alongside their objects (#8525) 2020-05-05 19:49:38 -02:30
preferences.js Use string network and chain IDs (#8628) 2020-07-08 14:05:09 -07:00
threebox.js Move export defaults statements alongside their objects (#8525) 2020-05-05 19:49:38 -02:30
token-rates.js Fix TokenRatesController (#8780) 2020-06-10 16:53:37 -03:00