Skip to content

Commit 53f2911

Browse files
authored
Optimized find all references and reduced memory usage in VS (#8339)
* Added ItemKey.fsi/fsi. Added blank SemanticClassification.fs/fsi. * Raise disposed exception * Re-worked semantic classification. Renamed ItemKeyReader to ItemKeyStore. Exposing ItemKeyStore/Builder * Fixing build * Storing semantic classification * Caching semantic classification * Wiring it up * Need to fix lexing * Added experimental lexing API to handle find all refs syntactic classification from allocating a lot * Added System.Memory * Using Span to check equality without allocating * Allocate less * Fixing build. Reducing more allocations and not using lex filter on lexing tokens. * Remove langversion * Fixed record find all refs * Fixing test * Partial match for active pattern * Feedback changes * Added comment on TcResolutionsExtensions * Creating view accessor when needed in ItemKey. Fixed UnionCase find all refs. * Added comment on warning * Added Range.comparer. Moving opens to top of file * More feedback changes * Added comment on sliding expiration
1 parent 9b29c43 commit 53f2911

32 files changed

+1921
-274
lines changed

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<SystemThreadingThreadPoolVersion>4.3.0</SystemThreadingThreadPoolVersion>
9797
<SystemValueTupleVersion>4.5.0</SystemValueTupleVersion>
9898
<SystemBuffersVersion>4.5.0</SystemBuffersVersion>
99+
<SystemMemoryVersion>4.5.3</SystemMemoryVersion>
99100
<!-- Roslyn packages -->
100101
<MicrosoftCodeAnalysisEditorFeaturesVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesVersion>
101102
<MicrosoftCodeAnalysisEditorFeaturesTextVersion>$(RoslynVersion)</MicrosoftCodeAnalysisEditorFeaturesTextVersion>

fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,18 @@
573573
<Compile Include="$(FSharpSourcesRoot)\fsharp\service\Reactor.fs">
574574
<Link>Service/Reactor.fs</Link>
575575
</Compile>
576+
<Compile Include="$(FSharpSourcesRoot)\fsharp\service\SemanticClassification.fsi">
577+
<Link>Service/SemanticClassification.fsi</Link>
578+
</Compile>
579+
<Compile Include="$(FSharpSourcesRoot)\fsharp\service\SemanticClassification.fs">
580+
<Link>Service/SemanticClassification.fs</Link>
581+
</Compile>
582+
<Compile Include="$(FSharpSourcesRoot)\fsharp\service\ItemKey.fsi">
583+
<Link>Service/ItemKey.fsi</Link>
584+
</Compile>
585+
<Compile Include="$(FSharpSourcesRoot)\fsharp\service\ItemKey.fs">
586+
<Link>Service/ItemKey.fs</Link>
587+
</Compile>
576588
<Compile Include="$(FSharpSourcesRoot)\fsharp\service\IncrementalBuild.fsi">
577589
<Link>Service/IncrementalBuild.fsi</Link>
578590
</Compile>
@@ -681,6 +693,7 @@
681693
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
682694
<PackageReference Include="System.Reflection.Metadata" Version="1.6.0" />
683695
<PackageReference Include="System.Buffers" Version="4.5.0" />
696+
<PackageReference Include="System.Memory" Version="4.5.3" />
684697
</ItemGroup>
685698
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
686699
<PackageReference Include="System.Diagnostics.Process" Version="4.1.0" />

src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<BuiltProjectOutputGroupKeyOutput Include="$(BuildOutputGroupLocation)\System.Reflection.Metadata.dll" />
2929
<BuiltProjectOutputGroupKeyOutput Include="$(BuildOutputGroupLocation)\System.Collections.Immutable.dll" />
3030
<BuiltProjectOutputGroupKeyOutput Include="$(BuildOutputGroupLocation)\System.Buffers.dll" />
31+
<BuiltProjectOutputGroupKeyOutput Include="$(BuildOutputGroupLocation)\System.Memory.dll" />
3132
</ItemGroup>
3233
</Target>
3334

@@ -579,6 +580,18 @@
579580
</Compile>
580581

581582
<!-- the incremental builder and service . -->
583+
<Compile Include="..\service\SemanticClassification.fsi">
584+
<Link>Service/SemanticClassification.fsi</Link>
585+
</Compile>
586+
<Compile Include="..\service\SemanticClassification.fs">
587+
<Link>Service/SemanticClassification.fs</Link>
588+
</Compile>
589+
<Compile Include="..\service\ItemKey.fsi">
590+
<Link>Service/ItemKey.fsi</Link>
591+
</Compile>
592+
<Compile Include="..\service\ItemKey.fs">
593+
<Link>Service/ItemKey.fs</Link>
594+
</Compile>
582595
<Compile Include="..\service\IncrementalBuild.fsi">
583596
<Link>Service/IncrementalBuild.fsi</Link>
584597
</Compile>
@@ -745,6 +758,7 @@
745758
<PackageReference Include="System.Threading.Thread" Version="$(SystemThreadingThreadVersion)" />
746759
<PackageReference Include="System.Threading.ThreadPool" Version="$(SystemThreadingThreadPoolVersion)" />
747760
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
761+
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
748762
</ItemGroup>
749763

750764
</Project>

src/fsharp/FSharp.Compiler.nuget/Microsoft.FSharp.Compiler.nuspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<dependency id="System.Threading.ThreadPool" version="4.3.0" />
2424
<dependency id="System.ValueTuple" version="4.4.0" />
2525
<dependency id="System.Buffers" version="4.5.0" />
26+
<dependency id="System.Memory" version="4.5.3" />
2627
</group>
2728
</dependencies>
2829
<contentFiles>

src/fsharp/NameResolution.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,9 @@ type TcResultsSinkImpl(g, ?sourceText: ISourceText) =
17571757
member this.GetOpenDeclarations() =
17581758
capturedOpenDeclarations |> Seq.distinctBy (fun x -> x.Range, x.AppliedScope, x.IsOwnNamespace) |> Seq.toArray
17591759

1760+
member this.GetFormatSpecifierLocations() =
1761+
capturedFormatSpecifierLocations.ToArray()
1762+
17601763
interface ITypecheckResultsSink with
17611764
member sink.NotifyEnvWithScope(m, nenv, ad) =
17621765
if allowedRange m then

src/fsharp/NameResolution.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ type internal TcResultsSinkImpl =
438438
/// Get all open declarations reported to the sink
439439
member GetOpenDeclarations : unit -> OpenDeclaration[]
440440

441+
/// Get the format specifier locations
442+
member GetFormatSpecifierLocations : unit -> (range * int)[]
443+
441444
interface ITypecheckResultsSink
442445

443446
/// An abstract type for reporting the results of name resolution and type checking, and which allows

src/fsharp/lexhelp.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ type LightSyntaxStatus(initial:bool,warn:bool) =
3636

3737
/// Manage lexer resources (string interning)
3838
[<Sealed>]
39-
type LexResourceManager() =
40-
let strings = new System.Collections.Generic.Dictionary<string, Parser.token>(1024)
39+
type LexResourceManager(?capacity: int) =
40+
let strings = new System.Collections.Generic.Dictionary<string, Parser.token>(defaultArg capacity 1024)
4141
member x.InternIdentifierToken(s) =
4242
match strings.TryGetValue s with
4343
| true, res -> res

src/fsharp/lexhelp.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type LightSyntaxStatus =
2525

2626
[<Sealed>]
2727
type LexResourceManager =
28-
new : unit -> LexResourceManager
28+
new : ?capacity: int -> LexResourceManager
2929

3030
type lexargs =
3131
{ defines: string list

src/fsharp/range.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module FSharp.Compiler.Range
55

66
open System
77
open System.IO
8+
open System.Collections.Generic
89
open System.Collections.Concurrent
910
open Microsoft.FSharp.Core.Printf
1011
open FSharp.Compiler.AbstractIL.Internal.Library
@@ -380,4 +381,9 @@ module Range =
380381

381382
let toFileZ (m:range) = m.FileName, toZ m
382383

384+
let comparer =
385+
{ new IEqualityComparer<range> with
386+
member _.Equals(x1, x2) = equals x1 x2
387+
member _.GetHashCode o = o.GetHashCode() }
388+
383389

src/fsharp/range.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,6 @@ module Range =
200200

201201
/// Convert a range from one-based line counting (used internally in the F# compiler and in F# error messages) to zero-based line counting (used by Visual Studio)
202202
val toFileZ : range -> string * Range01
203+
204+
/// Equality comparer for range.
205+
val comparer : IEqualityComparer<range>

0 commit comments

Comments
 (0)