Small speed up to _collection_changed (#90621)

attrgetter builds a fast method which happens in native code
4664a7cf68/Modules/_operator.c (L1413)
pull/90855/head
J. Nick Koston 2023-03-31 15:15:36 -10:00 committed by Paulus Schoutsen
parent d5d5bb0732
commit 1189b2ad70
1 changed files with 3 additions and 3 deletions

View File

@ -7,6 +7,7 @@ from collections.abc import Awaitable, Callable, Coroutine, Iterable
from dataclasses import dataclass
from itertools import groupby
import logging
from operator import attrgetter
from typing import Any, cast
import voluptuous as vol
@ -410,9 +411,8 @@ def sync_entity_lifecycle(
# Create a new bucket every time we have a different change type
# to ensure operations happen in order. We only group
# the same change type.
for _, grouped in groupby(
change_sets, lambda change_set: change_set.change_type
):
groupby_key = attrgetter("change_type")
for _, grouped in groupby(change_sets, groupby_key):
new_entities = [
entity
for entity in await asyncio.gather(