Commit 6681259
perf(analyzers): memoise compiled tree-sitter queries
AbstractAnalyzer._captures was recompiling its query string on every
call. cProfile on pytest-dev/pytest-6202 (204 files) showed
tree_sitter.Language.query consuming 3.03s of the 6.36s first_pass —
~48% of analyzer time spent rebuilding queries that never change.
Cache them on the analyzer instance, keyed by pattern string. Also
switches from the deprecated language.query() to the Query(language,
pattern) constructor.
Wall-time on pytest-6202 (CODE_GRAPH_PY_RESOLVER=tree_sitter):
before: 6.9s
after: 3.7s
Benefits every tree-sitter analyzer (Python, JavaScript, Kotlin), not
just the new static resolver.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 60ef625 commit 6681259
1 file changed
Lines changed: 12 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
14 | 24 | | |
15 | 25 | | |
16 | 26 | | |
17 | | - | |
18 | | - | |
| 27 | + | |
19 | 28 | | |
20 | 29 | | |
21 | 30 | | |
| |||
0 commit comments