-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Add find references functionality for JavaScript/TypeScript #1226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50c09f4
feat: Add find references functionality for JavaScript/TypeScript
misrasaurabh1 4a54486
feat: Integrate JS/TS find_references into optimization flow
misrasaurabh1 77f1eea
refactor: Move find_references into LanguageSupport abstraction
misrasaurabh1 6b7bafc
Improve find_references tests with value assertions and deduplication…
misrasaurabh1 026a63a
Update markdown tests to use full string equality assertions
misrasaurabh1 88999f0
Merge branch 'main' into feat/find-references-javascript
misrasaurabh1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚡️Codeflash found 105% (1.05x) speedup for
_extract_calling_function_pythonincodeflash/code_utils/code_extractor.py⏱️ Runtime :
81.6 milliseconds→39.8 milliseconds(best of156runs)📝 Explanation and details
The optimization achieves a 105% speedup (from 81.6ms to 39.8ms) by fundamentally changing how the AST is traversed to find the target function.
Key Performance Improvements:
Pruned Tree Traversal: The original code uses
ast.walk()which visits every node in the AST (~50,663 nodes in the profiler results). The optimized version uses an explicit stack withast.iter_child_nodes()and prunes entire subtrees whose line ranges cannot containref_line. This dramatically reduces nodes visited (only ~1,271 nodes in the optimized version) - a 97.5% reduction in node visits.Lazy Line Splitting: The original code eagerly calls
source_code.splitlines()upfront for every invocation. The optimized version only splits lines after finding a matching function, eliminating unnecessary string processing when returningNoneor for most iterations.Early Exit via Line Range Filtering: By checking
node_lineno <= ref_line <= node_end_linenobefore exploring children, the optimization avoids descending into AST branches that are guaranteed not to contain the reference line. This is especially effective when the target function is early in large files.Why This Matters:
From the line profiler, the original code spent 79.2% of time (257ms) just iterating through
ast.walk()and 6.8% (22ms) on isinstance checks across all nodes. The optimized version reduces this to 3.3% on child iteration and 0.1% on isinstance checks - spending most time on the unavoidableast.parse()instead.Test Case Performance:
test_extraction_performance_with_many_linesimproved from 54.9ms to 24.4ms (125% faster)ref_lineis outside function bounds, as early returns avoid full traversalThe optimization is particularly effective for large codebases and scenarios where the target function appears early in the file, as demonstrated by the 2-10x speedup in large-scale tests.
✅ Correctness verification report:
🌀 Click to see Generated Regression Tests
To test or edit this optimization locally
git merge codeflash/optimize-pr1226-2026-02-01T20.48.02Click to see suggested changes