feat(analyzers): tree-sitter Python symbol resolver (T18 #689)#691
Draft
DvirDukhan wants to merge 1 commit into
Draft
feat(analyzers): tree-sitter Python symbol resolver (T18 #689)#691DvirDukhan wants to merge 1 commit into
DvirDukhan wants to merge 1 commit into
Conversation
Replace jedi-based resolution with a pure tree-sitter static resolver
behind CODE_GRAPH_PY_RESOLVER=tree_sitter. Default remains jedi for
backwards compatibility.
Benchmark on pytest-dev/pytest-6202 (204 files):
- jedi: 247.1s wall, CALLS=1976, EXTENDS=71
- tree-sitter: 6.9s wall, CALLS=4833, EXTENDS=83
~36x speedup, broader call recall (jedi returns None ~80% of the time).
Mechanism:
- TreeSitterPythonResolver builds a project-wide symbol table
(top-level funcs/classes/assigns, class methods, import maps)
keyed by id(files) for lazy construction.
- Resolution: head lookup (local module -> import map ->
cross-project bare-name fallback) + tail walk through attributes
and class methods.
- Handles relative imports, aliased imports, import-of-package,
Optional[T]/generic_type subscript unwrapping.
- AbstractAnalyzer.needs_lsp() hook + PythonAnalyzer override let
source_analyzer skip LSP startup and venv setup entirely when
the static resolver is active. This is where the wall-time win
actually lives (jedi warm-up was ~240s of the 247s baseline).
Closes #689.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
DvirDukhan
added a commit
that referenced
this pull request
May 28, 2026
After T18 (#691) + query-cache (#692), code_graph indexing on pytest-6202 drops from 247s to 3.7s — but only if the API server is launched with CODE_GRAPH_PY_RESOLVER=tree_sitter. This helper bakes in that env plus the public/permissive flags the bench harness expects, so calibration runs hit the fast path without manual setup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Replaces jedi-based symbol resolution in
second_passwith a pure tree-sitter static resolver, opt-in viaCODE_GRAPH_PY_RESOLVER=tree_sitter. Default remains jedi for backwards compatibility.Stacked on #690 (T15 base class).
Benchmark — pytest-dev/pytest-6202 (204 files)
~36× speedup. DEFINES exact match. CALLS +145% (jedi returned None ~80% of the time; TS prefers recall). EXTENDS +17%.
Where the win lives
The headline isn't the resolver throughput — it's that
AbstractAnalyzer.needs_lsp()letssource_analyzerskip LSP startup and venv setup entirely when the static resolver is active. Jedi's warm-up was ~240s of the 247s baseline.Architecture
TreeSitterPythonResolver(api/analyzers/python/ts_resolver.py) builds a project-wide symbol table keyed byid(files).Optional[T]/generic_typesubscript unwrapping.AbstractAnalyzer.needs_lsp()hook +PythonAnalyzeroverride gates LSP startup andadd_dependenciesvenv install.Tests
16 unit tests in
tests/analyzers/test_ts_python_resolver.pycovering dotted-name parsing, path-to-module mapping, relative imports, aliased imports, import-of-package, class methods, env-var gating.Known follow-ups
language.query()toQuery()constructor (DeprecationWarning).Closes #689.