Avoid creating temporary lists (#25317)

That gives nano performance improvements as *() is slightly faster
then *[].
pull/25327/head
nierob 2019-07-19 20:36:18 +00:00 committed by Paulus Schoutsen
parent caa7a3a3d6
commit 979f801488
13 changed files with 42 additions and 42 deletions

View File

@ -38,8 +38,8 @@ async def auth_manager_from_config(
store = auth_store.AuthStore(hass)
if provider_configs:
providers = await asyncio.gather(
*[auth_provider_from_config(hass, store, config)
for config in provider_configs])
*(auth_provider_from_config(hass, store, config)
for config in provider_configs))
else:
providers = ()
# So returned auth providers are in same order as config
@ -50,8 +50,8 @@ async def auth_manager_from_config(
if module_configs:
modules = await asyncio.gather(
*[auth_mfa_module_from_config(hass, config)
for config in module_configs])
*(auth_mfa_module_from_config(hass, config)
for config in module_configs))
else:
modules = ()
# So returned auth modules are in same order as config

View File

@ -272,25 +272,25 @@ async def _async_set_up_integrations(
debuggers = domains & DEBUGGER_INTEGRATIONS
if debuggers:
_LOGGER.debug("Starting up debuggers %s", debuggers)
await asyncio.gather(*[
await asyncio.gather(*(
async_setup_component(hass, domain, config)
for domain in debuggers])
for domain in debuggers))
domains -= DEBUGGER_INTEGRATIONS
# Resolve all dependencies of all components so we can find the logging
# and integrations that need faster initialization.
resolved_domains_task = asyncio.gather(*[
resolved_domains_task = asyncio.gather(*(
loader.async_component_dependencies(hass, domain)
for domain in domains
], return_exceptions=True)
), return_exceptions=True)
# Set up core.
_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)
for domain in CORE_INTEGRATIONS
])):
))):
_LOGGER.error("Home Assistant core failed to initialize. "
"Further initialization aborted")
return
@ -312,10 +312,10 @@ async def _async_set_up_integrations(
if logging_domains:
_LOGGER.info("Setting up %s", logging_domains)
await asyncio.gather(*[
await asyncio.gather(*(
async_setup_component(hass, domain, config)
for domain in logging_domains
])
))
# Kick off loading the registries. They don't need to be awaited.
asyncio.gather(
@ -324,18 +324,18 @@ async def _async_set_up_integrations(
hass.helpers.area_registry.async_get_registry())
if stage_1_domains:
await asyncio.gather(*[
await asyncio.gather(*(
async_setup_component(hass, domain, config)
for domain in stage_1_domains
])
))
# Load all integrations
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)
for domain in stage_2_domains
], return_exceptions=True):
), return_exceptions=True):
# Exceptions are handled in async_setup_component.
if (isinstance(int_or_exc, loader.Integration) and
int_or_exc.after_dependencies):
@ -360,10 +360,10 @@ async def _async_set_up_integrations(
_LOGGER.debug("Setting up %s", domains_to_load)
await asyncio.gather(*[
await asyncio.gather(*(
async_setup_component(hass, domain, config)
for domain in domains_to_load
])
))
last_load = domains_to_load
stage_2_domains -= domains_to_load
@ -373,10 +373,10 @@ async def _async_set_up_integrations(
if stage_2_domains:
_LOGGER.debug("Final set up: %s", stage_2_domains)
await asyncio.gather(*[
await asyncio.gather(*(
async_setup_component(hass, domain, config)
for domain in stage_2_domains
])
))
# Wrap up startup
await hass.async_block_till_done()

View File

@ -72,6 +72,6 @@ async def async_reproduce_states(hass: HomeAssistantType,
states: Iterable[State],
context: Optional[Context] = None) -> None:
"""Reproduce component states."""
await asyncio.gather(*[
await asyncio.gather(*(
_async_reproduce_states(hass, state, context)
for state in states])
for state in states))

View File

@ -57,10 +57,10 @@ async def async_get_device_automation_triggers(hass, device_id):
for entity in entities:
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)
for domain in domains
])
))
for device_trigger in device_triggers:
if device_trigger is not None:
triggers.extend(device_trigger)

View File

@ -95,10 +95,10 @@ async def async_extract_config(hass, config):
"""Extract device tracker config and split between legacy and modern."""
legacy = []
for platform in await asyncio.gather(*[
for platform in await asyncio.gather(*(
async_create_platform_type(hass, config, p_type, p_config)
for p_type, p_config in config_per_platform(config, DOMAIN)
]):
)):
if platform is None:
continue

View File

@ -81,11 +81,11 @@ async def async_devices_sync(hass, data, payload):
{'request_id': data.request_id},
context=data.context)
devices = await asyncio.gather(*[
devices = await asyncio.gather(*(
entity.sync_serialize() for entity in
async_get_entities(hass, data.config)
if data.config.should_expose(entity.state)
])
))
response = {
'agentUserId': data.config.agent_user_id or data.context.user_id,

View File

@ -82,6 +82,6 @@ async def async_reproduce_states(hass: HomeAssistantType,
states: Iterable[State],
context: Optional[Context] = None) -> None:
"""Reproduce component states."""
await asyncio.gather(*[
await asyncio.gather(*(
_async_reproduce_states(hass, state, context)
for state in states])
for state in states))

View File

@ -245,10 +245,10 @@ class NextBusDepartureSensor(Entity):
))
# Chain all predictions together
predictions = list(chain(*[
predictions = list(chain(*(
listify(direction.get('prediction', []))
for direction in directions
]))
)))
# Short circuit if we don't have any actual bus predictions
if not predictions:

View File

@ -109,8 +109,8 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
device.label, device.device_id, exc_info=True)
devices.remove(device)
await asyncio.gather(*[retrieve_device_status(d)
for d in devices.copy()])
await asyncio.gather(*(retrieve_device_status(d)
for d in devices.copy()))
# Sync device subscriptions
await smartapp_sync_subscriptions(

View File

@ -65,10 +65,10 @@ async def handle_info(hass: HomeAssistantType,
await hass.helpers.system_info.async_get_system_info()
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
in info_callbacks.values()
])):
))):
data[domain] = domain_data
connection.send_message(websocket_api.result_message(msg['id'], data))

View File

@ -189,9 +189,9 @@ async def async_get_all_descriptions(hass):
loaded = {}
if missing:
contents = await asyncio.gather(*[
contents = await asyncio.gather(*(
_load_services_file(hass, domain) for domain in missing
])
))
for domain, content in zip(missing, contents):
loaded[domain] = content

View File

@ -140,10 +140,10 @@ async def async_reproduce_state(
if to_call:
# run all domains in parallel
await asyncio.gather(*[
await asyncio.gather(*(
worker(domain, data)
for domain, data in to_call.items()
])
))
@bind_hass

View File

@ -83,14 +83,14 @@ async def _async_get_custom_components(
dirs = await hass.async_add_executor_job(
get_sub_directories, custom_components.__path__)
integrations = await asyncio.gather(*[
integrations = await asyncio.gather(*(
hass.async_add_executor_job(
Integration.resolve_from_root,
hass,
custom_components,
comp.name)
for comp in dirs
])
))
return {
integration.domain: integration