From 7dcf27596670f8a341082bef5a19a85cc467a71a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 7 Mar 2024 23:30:31 -1000 Subject: [PATCH] Speed up importing mqtt platforms (#112682) Use async_forward_entry_setups so platforms can be loaded in a single executor job instead of many: Currently they all have to create a new job because it did not use async_forward_entry_setups ``` 2024-03-08 08:29:29.819 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[light] loop=[] took 12.12s 2024-03-08 08:29:29.822 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[number] loop=[] took 12.12s 2024-03-08 08:29:29.826 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[scene] loop=[] took 12.13s 2024-03-08 08:29:29.829 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[select] loop=[] took 12.13s 2024-03-08 08:29:29.833 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[sensor] loop=[] took 12.14s 2024-03-08 08:29:30.882 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[update] loop=[] took 13.18s 2024-03-08 08:29:30.948 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[button] loop=[] took 13.18s 2024-03-08 08:29:30.949 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[climate] loop=[] took 13.19s 2024-03-08 08:29:31.012 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[fan] loop=[] took 13.25s 2024-03-08 08:29:31.019 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[humidifier] loop=[] took 13.25s 2024-03-08 08:29:31.024 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[image] loop=[] took 13.26s 2024-03-08 08:29:31.034 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[lock] loop=[] took 13.27s 2024-03-08 08:29:31.045 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[vacuum] loop=[] took 13.28s 2024-03-08 08:29:31.050 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[valve] loop=[] took 13.28s ``` --- homeassistant/components/mqtt/__init__.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 7da8636b19b..279dbc57c84 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -40,6 +40,7 @@ from homeassistant.helpers.reload import async_integration_yaml_config from homeassistant.helpers.service import async_register_admin_service from homeassistant.helpers.typing import ConfigType from homeassistant.loader import async_get_integration +from homeassistant.util.async_ import create_eager_task # Loading the config flow file will register the flow from . import debug_info, discovery @@ -449,14 +450,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # Forward the entry setup to the MQTT platforms await asyncio.gather( *( - [ - device_automation.async_setup_entry(hass, config_entry), - tag.async_setup_entry(hass, config_entry), - ] - + [ - hass.config_entries.async_forward_entry_setup(entry, component) - for component in PLATFORMS - ] + create_eager_task( + device_automation.async_setup_entry(hass, config_entry) + ), + create_eager_task(tag.async_setup_entry(hass, config_entry)), + create_eager_task( + hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + ), ) ) # Setup discovery