You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native token lookup allocates a visitor on each AST descent step #64929
astnav.getTokenAtPosition calls VisitEachChildAndJSDoc at each descent step. The helper creates a new NodeVisitor and its hooks each time, although the callbacks stay the same throughout a lookup.
Profiling a tool that queries types through the native API showed these repeated allocations. Reusing the visitor reduced allocations in the isolated lookup benchmark below. The full workload did not show a clear timing improvement.
Reproduction
Base revision: a91e938. Environment: Go 1.27.1, darwin-arm64, Apple M3 Pro. I have not investigated when this behavior was introduced.
Append this benchmark to tsc/internal/astnav/tokens_test.go on the base revision (the file already has the imports):
go -C tsc test ./internal/astnav -run '^$' -bench BenchmarkGetTokenAtPositionNested -benchmem -count=5
Results
Medians of five runs, comparing the base revision with the visitor-reuse patch in #64928:
Before
After
Time
6.87 µs/op
1.24 µs/op
Allocated bytes
41,536 B/op
1,664 B/op
Allocations
153/op
13/op
This benchmark measures an identifier lookup inside 24 nested calls. The proposed change creates one visitor per lookup and reuses it during descent, while retaining child and JSDoc traversal and the exported helper signature. These measurements do not establish an overall compiler or language-service speedup.
AI assistance: Codex assisted in authoring and testing the patch and preparing this report.
Activity