mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 07:17:12 +00:00
Avoid creating temporary lists (#25317)
That gives nano performance improvements as *() is slightly faster then *[].
This commit is contained in:
parent
caa7a3a3d6
commit
979f801488
@ -38,8 +38,8 @@ async def auth_manager_from_config(
|
|||||||
store = auth_store.AuthStore(hass)
|
store = auth_store.AuthStore(hass)
|
||||||
if provider_configs:
|
if provider_configs:
|
||||||
providers = await asyncio.gather(
|
providers = await asyncio.gather(
|
||||||
*[auth_provider_from_config(hass, store, config)
|
*(auth_provider_from_config(hass, store, config)
|
||||||
for config in provider_configs])
|
for config in provider_configs))
|
||||||
else:
|
else:
|
||||||
providers = ()
|
providers = ()
|
||||||
# So returned auth providers are in same order as config
|
# So returned auth providers are in same order as config
|
||||||
@ -50,8 +50,8 @@ async def auth_manager_from_config(
|
|||||||
|
|
||||||
if module_configs:
|
if module_configs:
|
||||||
modules = await asyncio.gather(
|
modules = await asyncio.gather(
|
||||||
*[auth_mfa_module_from_config(hass, config)
|
*(auth_mfa_module_from_config(hass, config)
|
||||||
for config in module_configs])
|
for config in module_configs))
|
||||||
else:
|
else:
|
||||||
modules = ()
|
modules = ()
|
||||||
# So returned auth modules are in same order as config
|
# So returned auth modules are in same order as config
|
||||||
|
@ -272,25 +272,25 @@ async def _async_set_up_integrations(
|
|||||||
debuggers = domains & DEBUGGER_INTEGRATIONS
|
debuggers = domains & DEBUGGER_INTEGRATIONS
|
||||||
if debuggers:
|
if debuggers:
|
||||||
_LOGGER.debug("Starting up debuggers %s", debuggers)
|
_LOGGER.debug("Starting up debuggers %s", debuggers)
|
||||||
await asyncio.gather(*[
|
await asyncio.gather(*(
|
||||||
async_setup_component(hass, domain, config)
|
async_setup_component(hass, domain, config)
|
||||||
for domain in debuggers])
|
for domain in debuggers))
|
||||||
domains -= DEBUGGER_INTEGRATIONS
|
domains -= DEBUGGER_INTEGRATIONS
|
||||||
|
|
||||||
# Resolve all dependencies of all components so we can find the logging
|
# Resolve all dependencies of all components so we can find the logging
|
||||||
# and integrations that need faster initialization.
|
# and integrations that need faster initialization.
|
||||||
resolved_domains_task = asyncio.gather(*[
|
resolved_domains_task = asyncio.gather(*(
|
||||||
loader.async_component_dependencies(hass, domain)
|
loader.async_component_dependencies(hass, domain)
|
||||||
for domain in domains
|
for domain in domains
|
||||||
], return_exceptions=True)
|
), return_exceptions=True)
|
||||||
|
|
||||||
# Set up core.
|
# Set up core.
|
||||||
_LOGGER.debug("Setting up %s", CORE_INTEGRATIONS)
|
_LOGGER.debug("Setting up %s", CORE_INTEGRATIONS)
|
||||||
|
|
||||||
if not all(await asyncio.gather(*[
|
if not all(await asyncio.gather(*(
|
||||||
async_setup_component(hass, domain, config)
|
async_setup_component(hass, domain, config)
|
||||||
for domain in CORE_INTEGRATIONS
|
for domain in CORE_INTEGRATIONS
|
||||||
])):
|
))):
|
||||||
_LOGGER.error("Home Assistant core failed to initialize. "
|
_LOGGER.error("Home Assistant core failed to initialize. "
|
||||||
"Further initialization aborted")
|
"Further initialization aborted")
|
||||||
return
|
return
|
||||||
@ -312,10 +312,10 @@ async def _async_set_up_integrations(
|
|||||||
if logging_domains:
|
if logging_domains:
|
||||||
_LOGGER.info("Setting up %s", logging_domains)
|
_LOGGER.info("Setting up %s", logging_domains)
|
||||||
|
|
||||||
await asyncio.gather(*[
|
await asyncio.gather(*(
|
||||||
async_setup_component(hass, domain, config)
|
async_setup_component(hass, domain, config)
|
||||||
for domain in logging_domains
|
for domain in logging_domains
|
||||||
])
|
))
|
||||||
|
|
||||||
# Kick off loading the registries. They don't need to be awaited.
|
# Kick off loading the registries. They don't need to be awaited.
|
||||||
asyncio.gather(
|
asyncio.gather(
|
||||||
@ -324,18 +324,18 @@ async def _async_set_up_integrations(
|
|||||||
hass.helpers.area_registry.async_get_registry())
|
hass.helpers.area_registry.async_get_registry())
|
||||||
|
|
||||||
if stage_1_domains:
|
if stage_1_domains:
|
||||||
await asyncio.gather(*[
|
await asyncio.gather(*(
|
||||||
async_setup_component(hass, domain, config)
|
async_setup_component(hass, domain, config)
|
||||||
for domain in stage_1_domains
|
for domain in stage_1_domains
|
||||||
])
|
))
|
||||||
|
|
||||||
# Load all integrations
|
# Load all integrations
|
||||||
after_dependencies = {} # type: Dict[str, Set[str]]
|
after_dependencies = {} # type: Dict[str, Set[str]]
|
||||||
|
|
||||||
for int_or_exc in await asyncio.gather(*[
|
for int_or_exc in await asyncio.gather(*(
|
||||||
loader.async_get_integration(hass, domain)
|
loader.async_get_integration(hass, domain)
|
||||||
for domain in stage_2_domains
|
for domain in stage_2_domains
|
||||||
], return_exceptions=True):
|
), return_exceptions=True):
|
||||||
# Exceptions are handled in async_setup_component.
|
# Exceptions are handled in async_setup_component.
|
||||||
if (isinstance(int_or_exc, loader.Integration) and
|
if (isinstance(int_or_exc, loader.Integration) and
|
||||||
int_or_exc.after_dependencies):
|
int_or_exc.after_dependencies):
|
||||||
@ -360,10 +360,10 @@ async def _async_set_up_integrations(
|
|||||||
|
|
||||||
_LOGGER.debug("Setting up %s", domains_to_load)
|
_LOGGER.debug("Setting up %s", domains_to_load)
|
||||||
|
|
||||||
await asyncio.gather(*[
|
await asyncio.gather(*(
|
||||||
async_setup_component(hass, domain, config)
|
async_setup_component(hass, domain, config)
|
||||||
for domain in domains_to_load
|
for domain in domains_to_load
|
||||||
])
|
))
|
||||||
|
|
||||||
last_load = domains_to_load
|
last_load = domains_to_load
|
||||||
stage_2_domains -= domains_to_load
|
stage_2_domains -= domains_to_load
|
||||||
@ -373,10 +373,10 @@ async def _async_set_up_integrations(
|
|||||||
if stage_2_domains:
|
if stage_2_domains:
|
||||||
_LOGGER.debug("Final set up: %s", stage_2_domains)
|
_LOGGER.debug("Final set up: %s", stage_2_domains)
|
||||||
|
|
||||||
await asyncio.gather(*[
|
await asyncio.gather(*(
|
||||||
async_setup_component(hass, domain, config)
|
async_setup_component(hass, domain, config)
|
||||||
for domain in stage_2_domains
|
for domain in stage_2_domains
|
||||||
])
|
))
|
||||||
|
|
||||||
# Wrap up startup
|
# Wrap up startup
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -72,6 +72,6 @@ async def async_reproduce_states(hass: HomeAssistantType,
|
|||||||
states: Iterable[State],
|
states: Iterable[State],
|
||||||
context: Optional[Context] = None) -> None:
|
context: Optional[Context] = None) -> None:
|
||||||
"""Reproduce component states."""
|
"""Reproduce component states."""
|
||||||
await asyncio.gather(*[
|
await asyncio.gather(*(
|
||||||
_async_reproduce_states(hass, state, context)
|
_async_reproduce_states(hass, state, context)
|
||||||
for state in states])
|
for state in states))
|
||||||
|
@ -57,10 +57,10 @@ async def async_get_device_automation_triggers(hass, device_id):
|
|||||||
for entity in entities:
|
for entity in entities:
|
||||||
domains.add(split_entity_id(entity.entity_id)[0])
|
domains.add(split_entity_id(entity.entity_id)[0])
|
||||||
|
|
||||||
device_triggers = await asyncio.gather(*[
|
device_triggers = await asyncio.gather(*(
|
||||||
_async_get_device_automation_triggers(hass, domain, device_id)
|
_async_get_device_automation_triggers(hass, domain, device_id)
|
||||||
for domain in domains
|
for domain in domains
|
||||||
])
|
))
|
||||||
for device_trigger in device_triggers:
|
for device_trigger in device_triggers:
|
||||||
if device_trigger is not None:
|
if device_trigger is not None:
|
||||||
triggers.extend(device_trigger)
|
triggers.extend(device_trigger)
|
||||||
|
@ -95,10 +95,10 @@ async def async_extract_config(hass, config):
|
|||||||
"""Extract device tracker config and split between legacy and modern."""
|
"""Extract device tracker config and split between legacy and modern."""
|
||||||
legacy = []
|
legacy = []
|
||||||
|
|
||||||
for platform in await asyncio.gather(*[
|
for platform in await asyncio.gather(*(
|
||||||
async_create_platform_type(hass, config, p_type, p_config)
|
async_create_platform_type(hass, config, p_type, p_config)
|
||||||
for p_type, p_config in config_per_platform(config, DOMAIN)
|
for p_type, p_config in config_per_platform(config, DOMAIN)
|
||||||
]):
|
)):
|
||||||
if platform is None:
|
if platform is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -81,11 +81,11 @@ async def async_devices_sync(hass, data, payload):
|
|||||||
{'request_id': data.request_id},
|
{'request_id': data.request_id},
|
||||||
context=data.context)
|
context=data.context)
|
||||||
|
|
||||||
devices = await asyncio.gather(*[
|
devices = await asyncio.gather(*(
|
||||||
entity.sync_serialize() for entity in
|
entity.sync_serialize() for entity in
|
||||||
async_get_entities(hass, data.config)
|
async_get_entities(hass, data.config)
|
||||||
if data.config.should_expose(entity.state)
|
if data.config.should_expose(entity.state)
|
||||||
])
|
))
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
'agentUserId': data.config.agent_user_id or data.context.user_id,
|
'agentUserId': data.config.agent_user_id or data.context.user_id,
|
||||||
|
@ -82,6 +82,6 @@ async def async_reproduce_states(hass: HomeAssistantType,
|
|||||||
states: Iterable[State],
|
states: Iterable[State],
|
||||||
context: Optional[Context] = None) -> None:
|
context: Optional[Context] = None) -> None:
|
||||||
"""Reproduce component states."""
|
"""Reproduce component states."""
|
||||||
await asyncio.gather(*[
|
await asyncio.gather(*(
|
||||||
_async_reproduce_states(hass, state, context)
|
_async_reproduce_states(hass, state, context)
|
||||||
for state in states])
|
for state in states))
|
||||||
|
@ -245,10 +245,10 @@ class NextBusDepartureSensor(Entity):
|
|||||||
))
|
))
|
||||||
|
|
||||||
# Chain all predictions together
|
# Chain all predictions together
|
||||||
predictions = list(chain(*[
|
predictions = list(chain(*(
|
||||||
listify(direction.get('prediction', []))
|
listify(direction.get('prediction', []))
|
||||||
for direction in directions
|
for direction in directions
|
||||||
]))
|
)))
|
||||||
|
|
||||||
# Short circuit if we don't have any actual bus predictions
|
# Short circuit if we don't have any actual bus predictions
|
||||||
if not predictions:
|
if not predictions:
|
||||||
|
@ -109,8 +109,8 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
|||||||
device.label, device.device_id, exc_info=True)
|
device.label, device.device_id, exc_info=True)
|
||||||
devices.remove(device)
|
devices.remove(device)
|
||||||
|
|
||||||
await asyncio.gather(*[retrieve_device_status(d)
|
await asyncio.gather(*(retrieve_device_status(d)
|
||||||
for d in devices.copy()])
|
for d in devices.copy()))
|
||||||
|
|
||||||
# Sync device subscriptions
|
# Sync device subscriptions
|
||||||
await smartapp_sync_subscriptions(
|
await smartapp_sync_subscriptions(
|
||||||
|
@ -65,10 +65,10 @@ async def handle_info(hass: HomeAssistantType,
|
|||||||
await hass.helpers.system_info.async_get_system_info()
|
await hass.helpers.system_info.async_get_system_info()
|
||||||
|
|
||||||
if info_callbacks:
|
if info_callbacks:
|
||||||
for domain, domain_data in zip(info_callbacks, await asyncio.gather(*[
|
for domain, domain_data in zip(info_callbacks, await asyncio.gather(*(
|
||||||
_info_wrapper(hass, info_callback) for info_callback
|
_info_wrapper(hass, info_callback) for info_callback
|
||||||
in info_callbacks.values()
|
in info_callbacks.values()
|
||||||
])):
|
))):
|
||||||
data[domain] = domain_data
|
data[domain] = domain_data
|
||||||
|
|
||||||
connection.send_message(websocket_api.result_message(msg['id'], data))
|
connection.send_message(websocket_api.result_message(msg['id'], data))
|
||||||
|
@ -189,9 +189,9 @@ async def async_get_all_descriptions(hass):
|
|||||||
loaded = {}
|
loaded = {}
|
||||||
|
|
||||||
if missing:
|
if missing:
|
||||||
contents = await asyncio.gather(*[
|
contents = await asyncio.gather(*(
|
||||||
_load_services_file(hass, domain) for domain in missing
|
_load_services_file(hass, domain) for domain in missing
|
||||||
])
|
))
|
||||||
|
|
||||||
for domain, content in zip(missing, contents):
|
for domain, content in zip(missing, contents):
|
||||||
loaded[domain] = content
|
loaded[domain] = content
|
||||||
|
@ -140,10 +140,10 @@ async def async_reproduce_state(
|
|||||||
|
|
||||||
if to_call:
|
if to_call:
|
||||||
# run all domains in parallel
|
# run all domains in parallel
|
||||||
await asyncio.gather(*[
|
await asyncio.gather(*(
|
||||||
worker(domain, data)
|
worker(domain, data)
|
||||||
for domain, data in to_call.items()
|
for domain, data in to_call.items()
|
||||||
])
|
))
|
||||||
|
|
||||||
|
|
||||||
@bind_hass
|
@bind_hass
|
||||||
|
@ -83,14 +83,14 @@ async def _async_get_custom_components(
|
|||||||
dirs = await hass.async_add_executor_job(
|
dirs = await hass.async_add_executor_job(
|
||||||
get_sub_directories, custom_components.__path__)
|
get_sub_directories, custom_components.__path__)
|
||||||
|
|
||||||
integrations = await asyncio.gather(*[
|
integrations = await asyncio.gather(*(
|
||||||
hass.async_add_executor_job(
|
hass.async_add_executor_job(
|
||||||
Integration.resolve_from_root,
|
Integration.resolve_from_root,
|
||||||
hass,
|
hass,
|
||||||
custom_components,
|
custom_components,
|
||||||
comp.name)
|
comp.name)
|
||||||
for comp in dirs
|
for comp in dirs
|
||||||
])
|
))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
integration.domain: integration
|
integration.domain: integration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user