From 5034989188ade1b0041033a78a7fc609e2b5fca4 Mon Sep 17 00:00:00 2001 From: Tomasz Kontusz Date: Thu, 5 Sep 2019 07:53:01 +0200 Subject: [PATCH] Use identity instead of hash for caching subfields in collect_subfields This is closer to what GraphQL.js does, and performs much better: benchmark_executing_introspection_query went from Mean 1.1484 to 766.0428 --- src/graphql/execution/execute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphql/execution/execute.py b/src/graphql/execution/execute.py index 910b54d4..17656e94 100644 --- a/src/graphql/execution/execute.py +++ b/src/graphql/execution/execute.py @@ -205,7 +205,7 @@ def __init__( self.middleware_manager = middleware_manager self.errors = errors self._subfields_cache: Dict[ - Tuple[GraphQLObjectType, Tuple[FieldNode, ...]], Dict[str, List[FieldNode]] + Tuple[GraphQLObjectType, int], Dict[str, List[FieldNode]] ] = {} @classmethod @@ -998,7 +998,7 @@ def collect_subfields( subfields are not repeatedly calculated, which saves overhead when resolving lists of values. """ - cache_key = return_type, tuple(field_nodes) + cache_key = return_type, id(field_nodes) sub_field_nodes = self._subfields_cache.get(cache_key) if sub_field_nodes is None: sub_field_nodes = {}