-
Notifications
You must be signed in to change notification settings - Fork 707
Temporarily work around GetLineMap CPU usage #1368
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ type snapshot struct { | |
project *Project | ||
positionEncoding lsproto.PositionEncodingKind | ||
program *compiler.Program | ||
lineMaps collections.SyncMap[*ast.SourceFile, *ls.LineMap] | ||
} | ||
|
||
// GetLineMap implements ls.Host. | ||
|
@@ -51,7 +52,13 @@ func (s *snapshot) GetLineMap(fileName string) *ls.LineMap { | |
if s.project.getFileVersion(file) == scriptInfo.Version() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still don't really understand why we're doing this at all; it seems to me that we should not cache line maps on script infos at all, instead do it per-source-file, and then just always use that. But I seem to remember someone saying that was wrong for some reason, so, this hack seems better than nothing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recall a conversation around line maps differing between LS and CLI There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a different thing but yeah they do. |
||
return scriptInfo.LineMap() | ||
} | ||
return ls.ComputeLineStarts(file.Text()) | ||
// The version changed; recompute the line map. | ||
// !!! This shouldn't happen so often, but does. Probably removable once snapshotting is finished. | ||
if cached, ok := s.lineMaps.Load(file); ok { | ||
return cached | ||
} | ||
lineMap, _ := s.lineMaps.LoadOrStore(file, ls.ComputeLineStarts(file.Text())) | ||
return lineMap | ||
} | ||
|
||
// GetPositionEncoding implements ls.Host. | ||
|
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.
[nitpick] The
lineMaps
cache is unbounded and may retain entries even after files are closed or snapshots are discarded. Consider implementing eviction logic or clearing entries when files are removed to prevent potential memory growth.Copilot uses AI. Check for mistakes.
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.
No, these snapshots are request-scoped