mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-15 11:08:08 +00:00
feat(core): presize some modules to account for their sub-imports
This commit is contained in:
parent
5f4240d93c
commit
94521a2065
@ -6,7 +6,13 @@ import storage
|
|||||||
import storage.device
|
import storage.device
|
||||||
if __debug__:
|
if __debug__:
|
||||||
import storage.debug
|
import storage.debug
|
||||||
from trezor import config, pin, utils # noqa: F401
|
|
||||||
|
import trezor
|
||||||
|
import trezor.pin # noqa: F401
|
||||||
|
from trezor import utils
|
||||||
|
|
||||||
|
utils.presize_module("trezor", 30)
|
||||||
|
utils.presize_module("storage", 12)
|
||||||
|
|
||||||
if not utils.BITCOIN_ONLY:
|
if not utils.BITCOIN_ONLY:
|
||||||
import storage.fido2 # noqa: F401
|
import storage.fido2 # noqa: F401
|
||||||
|
@ -82,6 +82,20 @@ class unimport:
|
|||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
|
||||||
|
def presize_module(modname: str, size: int) -> None:
|
||||||
|
"""Ensure the module's dict is preallocated to an expected size.
|
||||||
|
|
||||||
|
This is used in modules like `trezor`, whose dict size depends not only on the
|
||||||
|
symbols defined in the file itself, but also on the number of submodules that will
|
||||||
|
be inserted into the module's namespace.
|
||||||
|
"""
|
||||||
|
module = sys.modules[modname]
|
||||||
|
for i in range(size):
|
||||||
|
setattr(module, "___PRESIZE_MODULE_%d" % i, None)
|
||||||
|
for i in range(size):
|
||||||
|
delattr(module, "___PRESIZE_MODULE_%d" % i)
|
||||||
|
|
||||||
|
|
||||||
def ensure(cond: bool, msg: str | None = None) -> None:
|
def ensure(cond: bool, msg: str | None = None) -> None:
|
||||||
if not cond:
|
if not cond:
|
||||||
if msg is None:
|
if msg is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user