From c8164dc164fb6840c7f3fdfc03b11e1a42d17d94 Mon Sep 17 00:00:00 2001 From: Monte Lai Date: Wed, 30 Apr 2025 22:16:55 +0800 Subject: [PATCH] perf: cache uuid --- .../src/AccountsController.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/accounts-controller/src/AccountsController.ts b/packages/accounts-controller/src/AccountsController.ts index 56c344e8849..6a793b59b99 100644 --- a/packages/accounts-controller/src/AccountsController.ts +++ b/packages/accounts-controller/src/AccountsController.ts @@ -44,6 +44,7 @@ import { isNormalKeyringType, keyringTypeToName, } from './utils'; +import { kill } from 'process'; const controllerName = 'AccountsController'; @@ -242,6 +243,10 @@ export const EMPTY_ACCOUNT = { }, }; +type AddressToUUIDCache = { + [address: string]: string; +}; + /** * Controller that manages internal accounts. * The accounts controller is responsible for creating and managing internal accounts. @@ -255,6 +260,8 @@ export class AccountsController extends BaseController< AccountsControllerState, AccountsControllerMessenger > { + #addressToUUIDCache: AddressToUUIDCache = {}; + /** * Constructor for AccountsController. * @@ -620,8 +627,15 @@ export class AccountsController extends BaseController< address: string, type: string, ): InternalAccount { + if (!this.#addressToUUIDCache[address]) { + this.#addressToUUIDCache[address] = + getUUIDFromAddressOfNormalAccount(address); + } + + const id = this.#addressToUUIDCache[address]; + return { - id: getUUIDFromAddressOfNormalAccount(address), + id, address, options: {}, methods: [