From f7fdaadde08d568e84d47534995c567ec045ff43 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Mon, 30 Jan 2023 12:25:22 -0600 Subject: [PATCH] Performance improvements for Assist (#86966) * Move hassil recognize into executor * Bump hassil to 0.2.6 * Disable template parsing in name/area lists * Don't iterate over hass.config.components directly --- .../components/conversation/default_agent.py | 18 +++++++++++------- .../components/conversation/manifest.json | 2 +- homeassistant/package_constraints.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/conversation/default_agent.py b/homeassistant/components/conversation/default_agent.py index 4e029f4e025..c897d2e3b87 100644 --- a/homeassistant/components/conversation/default_agent.py +++ b/homeassistant/components/conversation/default_agent.py @@ -127,7 +127,9 @@ class DefaultAgent(AbstractConversationAgent): "name": self._make_names_list(), } - result = recognize(user_input.text, lang_intents.intents, slot_lists=slot_lists) + result = await self.hass.async_add_executor_job( + recognize, user_input.text, lang_intents.intents, slot_lists + ) if result is None: _LOGGER.debug("No intent was matched for '%s'", user_input.text) return _make_error_result( @@ -216,13 +218,15 @@ class DefaultAgent(AbstractConversationAgent): async def async_get_or_load_intents(self, language: str) -> LanguageIntents | None: """Load all intents of a language with lock.""" + hass_components = set(self.hass.config.components) async with self._lang_lock[language]: return await self.hass.async_add_executor_job( - self._get_or_load_intents, - language, + self._get_or_load_intents, language, hass_components ) - def _get_or_load_intents(self, language: str) -> LanguageIntents | None: + def _get_or_load_intents( + self, language: str, hass_components: set[str] + ) -> LanguageIntents | None: """Load all intents for language (run inside executor).""" lang_intents = self._lang_intents.get(language) @@ -235,7 +239,7 @@ class DefaultAgent(AbstractConversationAgent): # Check if any new components have been loaded intents_changed = False - for component in self.hass.config.components: + for component in hass_components: if component in loaded_components: continue @@ -361,7 +365,7 @@ class DefaultAgent(AbstractConversationAgent): for alias in entry.aliases: areas.append((alias, entry.id)) - self._areas_list = TextSlotList.from_tuples(areas) + self._areas_list = TextSlotList.from_tuples(areas, allow_template=False) return self._areas_list def _make_names_list(self) -> TextSlotList: @@ -387,7 +391,7 @@ class DefaultAgent(AbstractConversationAgent): # Default name names.append((state.name, state.entity_id, context)) - self._names_list = TextSlotList.from_tuples(names) + self._names_list = TextSlotList.from_tuples(names, allow_template=False) return self._names_list def _get_error_text( diff --git a/homeassistant/components/conversation/manifest.json b/homeassistant/components/conversation/manifest.json index e7445b190e8..ad49516fe57 100644 --- a/homeassistant/components/conversation/manifest.json +++ b/homeassistant/components/conversation/manifest.json @@ -2,7 +2,7 @@ "domain": "conversation", "name": "Conversation", "documentation": "https://www.home-assistant.io/integrations/conversation", - "requirements": ["hassil==0.2.5", "home-assistant-intents==2023.1.25"], + "requirements": ["hassil==0.2.6", "home-assistant-intents==2023.1.25"], "dependencies": ["http"], "codeowners": ["@home-assistant/core"], "quality_scale": "internal", diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 44bc99ea03c..373253def9c 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -21,7 +21,7 @@ cryptography==39.0.0 dbus-fast==1.84.0 fnvhash==0.1.0 hass-nabucasa==0.61.0 -hassil==0.2.5 +hassil==0.2.6 home-assistant-bluetooth==1.9.2 home-assistant-frontend==20230128.0 home-assistant-intents==2023.1.25 diff --git a/requirements_all.txt b/requirements_all.txt index 66d6ff16947..9ed6bbdcffd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -874,7 +874,7 @@ hass-nabucasa==0.61.0 hass_splunk==0.1.1 # homeassistant.components.conversation -hassil==0.2.5 +hassil==0.2.6 # homeassistant.components.tasmota hatasmota==0.6.3 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index bd568608fc0..1d505d66b48 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -666,7 +666,7 @@ habitipy==0.2.0 hass-nabucasa==0.61.0 # homeassistant.components.conversation -hassil==0.2.5 +hassil==0.2.6 # homeassistant.components.tasmota hatasmota==0.6.3