Skip to content

Commit 62dd9e4

Browse files
committed
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
1 parent e302c24 commit 62dd9e4

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/graphql/execution/execute.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ def __init__(
204204
self.type_resolver = type_resolver # type: ignore
205205
self.middleware_manager = middleware_manager
206206
self.errors = errors
207-
self._subfields_cache: Dict[
208-
Tuple[GraphQLObjectType, Tuple[FieldNode, ...]], Dict[str, List[FieldNode]]
209-
] = {}
207+
self._subfields_cache: Dict[Tuple[int, int], Dict[str, List[FieldNode]]] = {}
210208

211209
@classmethod
212210
def build(
@@ -998,7 +996,7 @@ def collect_subfields(
998996
subfields are not repeatedly calculated, which saves overhead when resolving
999997
lists of values.
1000998
"""
1001-
cache_key = return_type, tuple(field_nodes)
999+
cache_key = id(return_type), id(field_nodes)
10021000
sub_field_nodes = self._subfields_cache.get(cache_key)
10031001
if sub_field_nodes is None:
10041002
sub_field_nodes = {}

0 commit comments

Comments
 (0)