-
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
RoslynSource Text #1123
RoslynSource Text #1123
Conversation
faster at individual lines than Roslyn SourceText but slower at whole file creation
16995ae
to
b9e8693
Compare
08f7117
to
986231a
Compare
986231a
to
79ef7cc
Compare
open FSharp.UMX | ||
open System.Collections.Generic | ||
|
||
let fileContents = IO.File.ReadAllText(@"C:\Users\jimmy\Repositories\public\TheAngryByrd\span-playground\Romeo and Juliet by William Shakespeare.txt") |
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.
Using this a just a giant text file. Should I include it or leave as an exercise for the others?
Microsoft.CodeAnalysis.Text.TextSpan(startPosition, endPosition - startPosition) | ||
|
||
/// A SourceText with operations commonly used in FsAutocomplete | ||
type IFSACSourceText = |
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.
Extracted interface for FSAC's source text impl
static member Create(path: string<LocalPath>, text, version) = | ||
let touched = | ||
let path = UMX.untag path | ||
type ISourceTextFactory = |
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.
Interface for pivoting between implementations.
|
||
override _.GetHashCode() = |
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.
Taken from Fsharp repo
let sourceTextFactories: (string * ISourceTextFactory) list = [ | ||
"NamedText", NamedTextFactory() | ||
"RosylinSourceText", RoslynSourceTextFactory() | ||
] |
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.
Running tests for both SourceText implementations
4ab4c7e
to
744c2e9
Compare
744c2e9
to
d2469dc
Compare
d2469dc
to
0e06921
Compare
Formatting check is failing due to a bug in fantomas: fsprojects/fantomas#2914 |
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.
LGTM, how will folks opt into this? the FSAC extra args option in Ionide?
Yeah I gotta make an ionide side flag. |
WHAT
🤖 Generated by Copilot at a6a0682
Refactor
AdaptiveFSharpLspServer
to useIFSACSourceText
interface for source text representation and improve readability.🤖 Generated by Copilot at a6a0682
🔧📝🚀
WHY
This uses the SourceText from the
Microsoft.CodeAnalysis
package. The Visual Studio tooling uses this. The implementation here tends to give more favorable results when it comes to memory usage and reducing Large Object Heap allocations.I also have a very bespoke implementation I attempted awhile ago with FSharp.Data.Adaptive and handrolling a lot of text manipulation using Spans. This probably will get removed before this PR is ready.
Below are some of the benchmarks.
N
refers to the number of changes to a text file.This does seem like a win. It allocates about 25% less though it does report slower for lots of rapid changes.
Also after running
dotnet-trace collect -p <pid> --duration 00:00:30 --profile gc-verbose
and playing around with large files, we tend to not get hit with as many Large Object Heap issues.Things left to do:
HOW
🤖 Generated by Copilot at a6a0682
IFSACSourceText
instead of the typeNamedText
in various functions, to allow different implementations for different editors or scenarios (link, link, link)namedText
binding in thehandler
function inAdaptiveFSharpLspServer.fs
, to make the code more consistent and readable (link, link, link, link, link, link, link)