-
-
Notifications
You must be signed in to change notification settings - Fork 268
[composable-controller] perf: Optimize expensive reduce operations, fix metadata instantiation #4968
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
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. |
mcmire
left a comment
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
MajorLift
left a comment
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
mcmire
left a comment
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.
…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
ComposableControllerinstantiation contribute to downstream performance issues in our client apps' initialization times. Optimizing these operations may be especially impactful sinceComposableControllertakes large inputs consisting of all of the controllers used by a given client.Explanation
reduceoperations that create temporary objects on each iteration and replace with implementations that re-use their output objects.ComposableControllerto 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.controllersinput. This is now resolved by using a type object.References
@metamask/composable-controllerfrom^3.0.0to^10.0.0metamask-mobile#10441@metamask/composable-controllerfrom^3.0.0to^10.0.0metamask-mobile#10441 (comment)EngineService, Redux store metamask-mobile#12509Changelog
@metamask/composable-controllerChanged
ComposableControllerconstructor optioncontrollersand generic type argumentChildControllersare re-defined from an array of controller instances to an object that maps controller names to controller instances.ComposableControllerclass field objectsstateandmetadataexclude child controllers that do not extend fromBaseControllerorBaseControllerV1. Any non-controller entries that are passed into the constructor will be removed automatically.Fixed
ComposableControllerclass field objectmetadatanow assigns theStateMetadataProperty-type object{ persist: true, anonymous: true }to each child controller name.@metamask/base-controller@6.0.0.Checklist