-
Notifications
You must be signed in to change notification settings - Fork 156
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
More performance tweaks adaptive #1028
Closed
TheAngryByrd
wants to merge
19
commits into
ionide:main
from
TheAngryByrd:more-performance-tweaks-adaptive
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
51911b4
Fixes ResolveNamespace in nested modules
TheAngryByrd cfeb732
Adds tests to verify ResolveNamespace fix
TheAngryByrd f360a10
Fixes ResolveNamespace tests
TheAngryByrd 5d52b08
More tests around ResolveNamespace
TheAngryByrd 4801167
Clear caching on project load and incremental text support
TheAngryByrd 8a211c0
Simplifying File CancellionToken relationship
TheAngryByrd 6e444ee
Typecheck saved file first
TheAngryByrd b2fe464
Better completion handling
TheAngryByrd 0607407
Start things async to get type check results faster
TheAngryByrd 5247cb4
Speed up completions by using stale results
TheAngryByrd ef8f861
Better error handling for ModifyText
TheAngryByrd 1b6b489
More resilient Completion checks
TheAngryByrd 25cfb94
be more resilient with no finding typecheck result
TheAngryByrd 20d2b49
Revert forgetDocument changes
TheAngryByrd 4f8d379
Consolodated LSP Server settings
TheAngryByrd 8d94783
Formatting
TheAngryByrd 30796d3
Cleanup/formatting
TheAngryByrd a52eec6
fixes around cancellationtoken replacements
TheAngryByrd cdd7299
Formatting and refactoring
TheAngryByrd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,11 @@ open Ionide.ProjInfo.ProjectSystem | |
open FSharp.UMX | ||
open FSharp.Compiler.EditorServices | ||
open FSharp.Compiler.Symbols | ||
open Microsoft.Extensions.Caching.Memory | ||
open System | ||
open FsToolkit.ErrorHandling | ||
|
||
|
||
|
||
type Version = int | ||
|
||
|
@@ -26,6 +31,9 @@ type FSharpCompilerServiceChecker(hasAnalyzers) = | |
|
||
let entityCache = EntityCache() | ||
|
||
let mutable lastCheckResults: IMemoryCache = | ||
new MemoryCache(MemoryCacheOptions(SizeLimit = Nullable<_>(20L))) | ||
|
||
let checkerLogger = LogProvider.getLoggerByName "Checker" | ||
let optsLogger = LogProvider.getLoggerByName "Opts" | ||
|
||
|
@@ -227,14 +235,22 @@ type FSharpCompilerServiceChecker(hasAnalyzers) = | |
member __.ScriptTypecheckRequirementsChanged = | ||
scriptTypecheckRequirementsChanged.Publish | ||
|
||
/// This function is called when the entire environment is known to have changed for reasons not encoded in the ProjectOptions of any project/compilation. | ||
member _.ClearCaches() = | ||
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. Useful for major project changes like |
||
let oldlastCheckResults = lastCheckResults | ||
lastCheckResults <- new MemoryCache(MemoryCacheOptions(SizeLimit = Nullable<_>(20L))) | ||
oldlastCheckResults.Dispose() | ||
checker.InvalidateAll() | ||
checker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients() | ||
|
||
member __.ParseFile(fn: string<LocalPath>, source, fpo) = | ||
checkerLogger.info (Log.setMessage "ParseFile - {file}" >> Log.addContextDestructured "file" fn) | ||
|
||
let path = UMX.untag fn | ||
checker.ParseFile(path, source, fpo) | ||
|
||
member __.ParseAndCheckFileInProject(filePath: string<LocalPath>, version, source: ISourceText, options) = | ||
async { | ||
asyncResult { | ||
let opName = sprintf "ParseAndCheckFileInProject - %A" filePath | ||
|
||
checkerLogger.info (Log.setMessage "{opName}" >> Log.addContextDestructured "opName" opName) | ||
|
@@ -255,32 +271,58 @@ type FSharpCompilerServiceChecker(hasAnalyzers) = | |
>> Log.addContextDestructured "errors" (List.ofArray p.Diagnostics) | ||
) | ||
|
||
return ResultOrString.Error(sprintf "Check aborted (%A). Errors: %A" c parseErrors) | ||
return! ResultOrString.Error(sprintf "Check aborted (%A). Errors: %A" c parseErrors) | ||
| FSharpCheckFileAnswer.Succeeded (c) -> | ||
checkerLogger.info ( | ||
Log.setMessage "{opName} completed successfully" | ||
>> Log.addContextDestructured "opName" opName | ||
) | ||
|
||
return Ok(ParseAndCheckResults(p, c, entityCache)) | ||
let r = ParseAndCheckResults(p, c, entityCache) | ||
|
||
let ops = | ||
MemoryCacheEntryOptions() | ||
.SetSize(1) | ||
.SetSlidingExpiration(TimeSpan.FromMinutes(2.)) | ||
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. Not sure if a time is really needed. |
||
|
||
return lastCheckResults.Set(filePath, r, ops) | ||
with ex -> | ||
return ResultOrString.Error(ex.ToString()) | ||
return! ResultOrString.Error(ex.ToString()) | ||
} | ||
|
||
member _.TryGetLastCheckResultForFile(file: string<LocalPath>) = | ||
let opName = sprintf "TryGetLastCheckResultForFile - %A" file | ||
|
||
checkerLogger.info ( | ||
Log.setMessage "{opName}" >> Log.addContextDestructured "opName" opName | ||
|
||
) | ||
|
||
match lastCheckResults.TryGetValue<ParseAndCheckResults>(file) with | ||
| (true, v) -> Some v | ||
| _ -> None | ||
|
||
member __.TryGetRecentCheckResultsForFile(file: string<LocalPath>, options, source: ISourceText) = | ||
let opName = sprintf "TryGetRecentCheckResultsForFile - %A" file | ||
|
||
checkerLogger.info ( | ||
Log.setMessage "{opName} - {hash}" | ||
>> Log.addContextDestructured "opName" opName | ||
>> Log.addContextDestructured "hash" (source.GetHashCode() |> int) | ||
|
||
) | ||
|
||
let options = clearProjectReferences options | ||
|
||
let result = | ||
checker.TryGetRecentCheckResultsForFile(UMX.untag file, options, sourceText = source, userOpName = opName) | ||
|> Option.map (fun (pr, cr, _) -> ParseAndCheckResults(pr, cr, entityCache)) | ||
|> Option.map (fun (pr, cr, version) -> | ||
checkerLogger.info ( | ||
Log.setMessage "{opName} - got results - {version}" | ||
>> Log.addContextDestructured "version" version | ||
) | ||
|
||
ParseAndCheckResults(pr, cr, entityCache)) | ||
|
||
checkerLogger.info ( | ||
Log.setMessage "{opName} - {hash} - cacheHit {cacheHit}" | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
We can use stale results for completions to get it to be super quick. However the compiler's TryGetRecentTypeCheck only keeps type checks for the specific sourcetext, which won't really matter for us because we'll be doing incremental type checking on DidChange already