Perf: reduce allocations and redundant work in hot paths#1514
Open
Thorium wants to merge 1 commit intoionide:mainfrom
Open
Perf: reduce allocations and redundant work in hot paths#1514Thorium wants to merge 1 commit intoionide:mainfrom
Thorium wants to merge 1 commit intoionide:mainfrom
Conversation
Performance improvements: - FileSystem.fs: Cache Lines property on RoslynSourceTextFile via lazy, avoiding repeated Seq.toArray + Array.map on every access. Replace ToString().GetBytes() in GetFileContent with chunked ISourceText.CopyTo to avoid materializing the entire source as an intermediate string. Uses UTF8Encoding(false) to avoid BOM, matching original behavior. - Lexer.fs: Replace Array.fold with a simple for-loop for parsing defines and lang version from args. Each call creates its own FSharpSourceTokenizer (they are lightweight); no shared mutable state across threads. - CompilerServiceInterface.fs: Move normalizePath into each match branch of SourceFilesTagged to avoid an extra List.map pass. Replace quadratic Array.append fold in processFSIArgs with ResizeArray for O(n) behavior. - AdaptiveServerState.fs: Cache SourceFilesTagged on LoadedProject via a Lazy field and factory method, avoiding repeated List.map + List.toArray on every access. Replace OTel tag 'source.text' (which boxed entire file contents as a string) with 'source.length' (just the int length). - AdaptiveFSharpLspServer.fs: Add rereadFile parameter to completion retry logic so the file is only re-read when the error indicates stale content (e.g. line lookup failure, trigger char mismatch), not on every retry. The 'empty completions' case skips re-read since only typecheck matters.
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.
Performance improvements:
FileSystem.fs: Cache Lines property on RoslynSourceTextFile via lazy, avoiding repeated Seq.toArray + Array.map on every access. Replace ToString().GetBytes() in GetFileContent with chunked ISourceText.CopyTo to avoid materializing the entire source as an intermediate string. Uses UTF8Encoding(false) to avoid BOM, matching original behavior.
Lexer.fs: Replace Array.fold with a simple for-loop for parsing defines and lang version from args. Each call creates its own FSharpSourceTokenizer (they are lightweight); no shared mutable state across threads.
CompilerServiceInterface.fs: Move normalizePath into each match branch of SourceFilesTagged to avoid an extra List.map pass. Replace quadratic Array.append fold in processFSIArgs with ResizeArray for O(n) behavior.
AdaptiveServerState.fs: Cache SourceFilesTagged on LoadedProject via a Lazy field and factory method, avoiding repeated List.map + List.toArray on every access. Replace OTel tag 'source.text' (which boxed entire file contents as a string) with 'source.length' (just the int length).
AdaptiveFSharpLspServer.fs: Add rereadFile parameter to completion retry logic so the file is only re-read when the error indicates stale content (e.g. line lookup failure, trigger char mismatch), not on every retry. The 'empty completions' case skips re-read since only typecheck matters.