Cache binding occurrences for faster global references/rename/highlight#486
Merged
Cache binding occurrences for faster global references/rename/highlight#486
references/rename/highlight#486Conversation
Add `BindingOccurrencesCache` to cache `compute_binding_occurrences` results per top-level expression, keyed by byte range. This avoids redundant lowering and binding analysis when the same file is searched multiple times during global references or rename operations. Cache invalidation follows the same pattern as `document_symbol_cache`: - `textDocument/didChange` for synced files - `workspace/didChangeWatchedFiles` for unsynced files Note: Invalidation when full-analysis updates module context is not yet implemented (see TODO in types.jl).
Reduce cache memory usage from ~100MB to ~11MB by not storing full `JS.SyntaxTree` and `JL.BindingInfo` objects, which hold references to large internal structures (syntax graphs, lowering contexts). Instead, introduce lightweight cache types that store only the essential information needed for LSP operations: - `BindingInfoKey`: stores only `(mod, name)` from `BindingInfo` - `CachedSyntaxTree`: stores only byte range and source location - `CachedBindingOccurrence`: combines the above with binding kind `CachedSyntaxTree` implements the minimum `JS.SyntaxTree` API required by `jsobj_to_range`, maintaining compatibility with existing code via duck typing.
Refactor `global_document_highlights!` to use `find_global_binding_occurrences!`
instead of duplicating the binding occurrence computation logic. This
allows document highlight to benefit from the binding occurrences cache.
Also simplify function signatures by replacing the complex union type
`module_info::Union{Tuple{ServerState,URI},Module}` and optional
`location_info` keyword with required positional `state` and `uri`
arguments.
231c034 to
8a827a0
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #486 +/- ##
==========================================
+ Coverage 67.43% 67.51% +0.08%
==========================================
Files 46 46
Lines 6519 6539 +20
==========================================
+ Hits 4396 4415 +19
- Misses 2123 2124 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Cache
compute_binding_occurrencesresults per top-level expressionto avoid redundant lowering when searching the same file multiple times.
Changes
On-demand caching (18bddc7)
Add
BindingOccurrencesCachekeyed by top-level expression byte range. WhentextDocument/referencesortextDocument/renamesearches a file, the binding occurrence analysis is cached and reused for subsequent requests within the same analysis unit.Cache invalidation follows the same pattern as
document_symbol_cache:textDocument/didChangefor synced filesworkspace/didChangeWatchedFilesfor unsynced filesMemory optimization (0f6874d)
Full
JS.SyntaxTreeandJL.BindingInfoobjects hold references to large internal structures. Introduce lightweight types that store only what LSP operations need:BindingInfoKey:(mod, name)tupleCachedSyntaxTree: byte range and source location onlyCachedBindingOccurrence: combines above with binding kinddocument-highlight refactor (8a827a0)
Refactor
global_document_highlights!to usefind_global_binding_occurrences!, allowing document highlight to benefit from the cache.