Commit 023f21a
⚡️ Speed up function
* ⚡️ Speed up function `should_resolve_list_connection_edges` by 46%
Here is a rewritten, much faster version of your function.
The efficiency improvement focuses on two major issues in the profile.
- The **nested for-loops** iterating through selections and recursing with a function that checks every node. This was incurring deep call overhead and duplicate checks.
- The **recursive _check_selection** can be replaced with an iterative approach using a stack to avoid deep Python recursion and to exit immediately on the first match.
**Summary of changes:**
- Eliminated all recursion by rewriting as a single iterative DFS using a stack, minimizing Python frame overhead.
- Only a single scan through the selection tree with immediate exit on finding a match (`edges`/`pageInfo`).
- Preserved the public API and all comments as required.
- No repeated checks for the same node, no walk of already-matched subtrees.
**You can expect** a substantial runtime improvement, especially with deeply nested or large queries, plus removal of risk of hitting the recursion limit.
* Apply suggestions from code review
* Update strawberry/relay/utils.py
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
---------
Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>should_resolve_list_connection_edges by 46% (#3976)1 parent eb577c2 commit 023f21a
1 file changed
+9
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
96 | 92 | | |
97 | 93 | | |
98 | 94 | | |
99 | 95 | | |
100 | 96 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 97 | + | |
| 98 | + | |
111 | 99 | | |
112 | 100 | | |
113 | 101 | | |
| |||
0 commit comments