1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-22 21:22:22 +01:00

Reserve memory for component and platform vectors (#9042)

This commit is contained in:
J. Nick Koston
2025-06-11 05:05:42 -05:00
committed by GitHub
parent a488c8cd5c
commit 3411e45a0a
23 changed files with 125 additions and 10 deletions

View File

@@ -329,6 +329,12 @@ async def _add_automations(config):
await automation.build_automation(trigger, [], conf)
@coroutine_with_priority(-100.0)
async def _add_platform_reserves() -> None:
for platform_name, count in sorted(CORE.platform_counts.items()):
cg.add(cg.RawStatement(f"App.reserve_{platform_name}({count});"), prepend=True)
@coroutine_with_priority(100.0)
async def to_code(config):
cg.add_global(cg.global_ns.namespace("esphome").using)
@@ -347,6 +353,12 @@ async def to_code(config):
config[CONF_NAME_ADD_MAC_SUFFIX],
)
)
# Reserve space for components to avoid reallocation during registration
cg.add(
cg.RawStatement(f"App.reserve_components({len(CORE.component_ids)});"),
)
CORE.add_job(_add_platform_reserves)
CORE.add_job(_add_automations, config)