-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
[composable-controller] perf: Optimize expensive reduce operations, fix metadata instantiation #4968
[composable-controller] perf: Optimize expensive reduce operations, fix metadata instantiation #4968
Conversation
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
c09346e
to
2b9717c
Compare
@metamaskbot publish-preview |
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
@metamaskbot publish-preview |
…eating new tmp object every iteration
…non-V2 controllers
…leController state and metadata fields
…ted properties of child controller state
…messenger events allowlists
…ller name object keys
a0b32c1
to
244f6c8
Compare
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a few suggestions/questions.
packages/composable-controller/src/ComposableController.test.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add links to changelog entries
…move-expensive-reduce
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…`^10.0.0` (#10441) ## **Description** This commit updates `@metamask/composable-controller` to `^10.0.0`. This involves fixing bugs outlined in #10073, and applying the major changes to the `ComposableController` API that has accumulated between the intervening versions. ## Blocked by - MetaMask/core#4968 - `composable-controller` v10 has been written to ensure that the effect of this optimization is maximized. - #12348 - #12407 - ~#11162 ## Changelog ### Changed - **BREAKING:** Bump `@metamask/composable-controller` from `^3.0.0` to `^10.0.0`. - **BREAKING:** Instantiate `ComposableController` class constructor option `messenger` with a `RestrictedControllerMessenger` instance derived from the `controllerMessenger` class field instance of `Engine`, instead of passing in the unrestricted `controllerMessenger` instance directly. - **BREAKING:** Narrow external actions allowlist for `messenger` instance passed into `ComposableController` constructor from `GlobalActions['type']` to an empty union. - **BREAKING:** Narrow external events allowlist for `messenger` instance passed into `ComposableController` constructor from `GlobalEvents['type']` to a union of the `stateChange` events of all controllers included in the `EngineState` type. - Convert the `EngineState` interface to use type alias syntax to ensure compatibility with types used in MetaMask controllers. ### Fixed - **BREAKING:** Narrow `Engine` class `datamodel` field from `any` to `ComposableController<EngineState, StatefulControllers>`. - **BREAKING:** The `CurrencyRatesController` constructor now normalizes `null` into 0 for the `conversionRate` values of all native currencies keyed in the `currencyRates` object of `CurrencyRatesControllerState`. - Restore previously suppressed type-level validation for `ComposableController` constructor option `controllers`. ## **Related issues** - Closes #10073 - Applies MetaMask/core#4467 - Blocked by `@metamask/composable-controller@8.0.0` release. - Supersedes #10011 ## **Manual testing steps** ## **Screenshots/Recordings** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Salah-Eddine Saakoun <salah-eddine.saakoun@consensys.net>
…12509) ## **Description** - ~Define types: `ReduxStore`, `ReduxState`~ (superseded by #12538) - Fix `any` types in `EngineService`. - Optimize `EngineService` event subscriptions: - Fix `update_bg_state_cb` callback being re-defined on every iteration. - Consolidate `stateChange` events collections into `BACKGROUND_STATE_CHANGE_EVENT_NAMES` constant for maintainability. ## **Related issues** - Blocked by #10441 - Blocked by MetaMask/core#4968 and corresponding release. ## **Manual testing steps** ## **Screenshots/Recordings** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
Motivation
Expensive operations during
ComposableController
instantiation contribute to downstream performance issues in our client apps' initialization times. Optimizing these operations may be especially impactful sinceComposableController
takes large inputs consisting of all of the controllers used by a given client.Explanation
reduce
operations that create temporary objects on each iteration and replace with implementations that re-use their output objects.ComposableController
to accept an object instead of an array. Now that the mobile Engine creates a controllers object, this saves us an extra operation for converting the object into an array.controllers
input. This is now resolved by using a type object.References
@metamask/composable-controller
from^3.0.0
to^10.0.0
metamask-mobile#10441@metamask/composable-controller
from^3.0.0
to^10.0.0
metamask-mobile#10441 (comment)EngineService
, Redux store metamask-mobile#12509Changelog
@metamask/composable-controller
Changed
ComposableController
constructor optioncontrollers
and generic type argumentChildControllers
are re-defined from an array of controller instances to an object that maps controller names to controller instances.ComposableController
class field objectsstate
andmetadata
exclude child controllers that do not extend fromBaseController
orBaseControllerV1
. Any non-controller entries that are passed into the constructor will be removed automatically.Fixed
ComposableController
class field objectmetadata
now assigns theStateMetadataProperty
-type object{ persist: true, anonymous: true }
to each child controller name.@metamask/base-controller@6.0.0
.Checklist