Skip to content

⚡️ Speed up function _get_all_json_refs by 91.64%#312

Open
codeflash-ai[bot] wants to merge 1 commit intomainfrom
codeflash/optimize-_get_all_json_refs-mnho62qe
Open

⚡️ Speed up function _get_all_json_refs by 91.64%#312
codeflash-ai[bot] wants to merge 1 commit intomainfrom
codeflash/optimize-_get_all_json_refs-mnho62qe

Conversation

@codeflash-ai
Copy link
Copy Markdown

@codeflash-ai codeflash-ai bot commented Apr 2, 2026

📄 91.64% (0.92x) speedup for _get_all_json_refs in src/algorithms/search.py

⏱️ Runtime : 2.42 milliseconds 1.26 milliseconds (best of 171 runs)

📝 Explanation and details

The _get_all_json_refs function was rewritten from recursive traversal to an iterative stack-based approach, achieving a 91% speedup (2.42ms → 1.26ms). Recursive calls in Python incur significant overhead from frame allocation and teardown on each nested dict/list, whereas the stack-based version amortizes this cost across the entire traversal with a single while-loop. The optimization is especially effective on deeply nested JSON schemas where recursive depth would trigger many function calls, now replaced by simple list append/extend operations.

Correctness verification report:

Test Status
📊 Tests Coverage Coverage: 100.0% for _get_all_json_refs

To edit these changes git checkout codeflash/optimize-_get_all_json_refs-mnho62qe and push.

Codeflash Static Badge

The `_get_all_json_refs` function was rewritten from recursive traversal to an iterative stack-based approach, achieving a 91% speedup (2.42ms → 1.26ms). Recursive calls in Python incur significant overhead from frame allocation and teardown on each nested dict/list, whereas the stack-based version amortizes this cost across the entire traversal with a single while-loop. The optimization is especially effective on deeply nested JSON schemas where recursive depth would trigger many function calls, now replaced by simple list append/extend operations.
@codeflash-ai codeflash-ai bot requested a review from KRRT7 April 2, 2026 16:08
@codeflash-ai codeflash-ai bot added ⚡️ codeflash Optimization PR opened by Codeflash AI 🎯 Quality: High Optimization Quality according to Codeflash labels Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚡️ codeflash Optimization PR opened by Codeflash AI 🎯 Quality: High Optimization Quality according to Codeflash

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants