Skip to content

Commit dd7a427

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 dd7a427

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/graphql/execution/execute.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def __init__(
205205
self.middleware_manager = middleware_manager
206206
self.errors = errors
207207
self._subfields_cache: Dict[
208-
Tuple[GraphQLObjectType, Tuple[FieldNode, ...]], Dict[str, List[FieldNode]]
208+
Tuple[int, int], Dict[str, List[FieldNode]]
209209
] = {}
210210

211211
@classmethod
@@ -998,7 +998,7 @@ def collect_subfields(
998998
subfields are not repeatedly calculated, which saves overhead when resolving
999999
lists of values.
10001000
"""
1001-
cache_key = return_type, tuple(field_nodes)
1001+
cache_key = id(return_type), id(field_nodes)
10021002
sub_field_nodes = self._subfields_cache.get(cache_key)
10031003
if sub_field_nodes is None:
10041004
sub_field_nodes = {}

0 commit comments

Comments
 (0)