Skip to content
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

Optimize completion #5066

Merged
merged 20 commits into from
Jun 5, 2018
Merged

Conversation

vasily-kirichenko
Copy link
Contributor

First invocation

Before

image

After

image

Second invocation

Before

image

After

image

Vasily Kirichenko added 2 commits June 1, 2018 15:55
do not generalize suppressed types twice
@cartermp
Copy link
Contributor

cartermp commented Jun 1, 2018

@dotnet-bot test this please

@vasily-kirichenko
Copy link
Contributor Author

@cartermp it's not compilable at the moment.

src/fsharp/symbols/SymbolHelpers.fs Outdated Show resolved Hide resolved
src/fsharp/service/ServiceAssemblyContent.fs Show resolved Hide resolved
src/fsharp/service/ServiceAssemblyContent.fs Outdated Show resolved Hide resolved
remove cancellation from CompletionProvider
@forki
Copy link
Contributor

forki commented Jun 2, 2018 via email

@vasily-kirichenko
Copy link
Contributor Author

@forki @smoothdeveloper all done, thanks.

@vasily-kirichenko
Copy link
Contributor Author

Before caching ILTypeDef.CustomAttrs

image

After

image

src/absil/il.fs Outdated Show resolved Hide resolved
@dsyme
Copy link
Contributor

dsyme commented Jun 2, 2018

This is great work!

@vasily-kirichenko
Copy link
Contributor Author

Before storing attrs in ILTypeDef (after executing completion in FSharp.Editor project):

image

After:

image

@vasily-kirichenko
Copy link
Contributor Author

vasily-kirichenko commented Jun 2, 2018

@dsyme Do I understand right that we still cannot use struct tuples in FSharp.Compiler.Private project?

@vasily-kirichenko
Copy link
Contributor Author

I spot a lack of fast comparer for bool values. This is number of allocations caused by a single completion popup on FSharp.Editor project:

image

After providing a comparer, it look like this:

image

It's eliminated 1M boxed bool and 700K tuples allocations.

@dsyme
Copy link
Contributor

dsyme commented Jun 2, 2018

Do I understand right that we still cannot use struct tuples in FSharp.Compiler.Private project?

You can if you really need to but can cause some problems with packaging various releases and the Fable build of the compiler - but it's normally clearer to introduce a named struct

@dsyme
Copy link
Contributor

dsyme commented Jun 2, 2018

I spot a lack of fast comparer for bool values.

@vasily-kirichenko Nice catch. We should put that change into F# 4.5. Could you isolate that 3-line change out into a separate PR?

@vasily-kirichenko
Copy link
Contributor Author

@dsyme done #5076

@vasily-kirichenko
Copy link
Contributor Author

You can if you really need to but can cause some problems with packaging various releases and the Fable build of the compiler - but it's normally clearer to introduce a named struct

OK, replacing tuples with structs needs benchmarking anyway.

@dsyme
Copy link
Contributor

dsyme commented Jun 2, 2018

Re Array.Empty, I meant:

type EmptyArray<'T>() = 
    static let empty = ([| |] : 'T [])
    static member Empty = empty

and so on. i.e. type-indexed by automagic of .NET generics.

.NET 4.something actually has Array.Empty() here:

> (System.Array.Empty() : int[]);;
val it : int [] = [||]

which is a singleton. Hwoever it's only available since .NET 4.6 and FSharp.Core needs to run on .NET 4.5. We could use it for .NET Standard though

@vasily-kirichenko
Copy link
Contributor Author

@dsyme I've added the array empty singleton.

@vasily-kirichenko
Copy link
Contributor Author

So, this makes completion 2x faster on FSharp.Editor project:

Master

image

This branch (release)

image

@vasily-kirichenko
Copy link
Contributor Author

It turns out that

open System
open BenchmarkDotNet
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running

type Test() =
    [<Benchmark(Baseline = true)>]
    member __.Sprintf() = sprintf "%06d" 123456

    [<Benchmark>]
    member __.Format() = (123456).ToString("D6")

[<EntryPoint>]
let main _ = 
    BenchmarkRunner.Run<Test>() |> ignore
    0
BenchmarkDotNet=v0.10.14, OS=Windows 10.0.17134
Intel Core i5-7600 CPU 3.50GHz (Kaby Lake), 1 CPU, 4 logical and 4 physical cores
  [Host]     : .NET Framework 4.6.1 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3101.0
  DefaultJob : .NET Framework 4.6.1 (CLR 4.0.30319.42000), 32bit LegacyJIT-v4.7.3101.0


  Method |     Mean |    Error |   StdDev | Scaled |
-------- |---------:|---------:|---------:|-------:|
 Sprintf | 340.3 ns | 5.908 ns | 5.237 ns |   1.00 |
  Format | 111.1 ns | 1.295 ns | 1.148 ns |   0.33 |

@vasily-kirichenko
Copy link
Contributor Author

@dotnet-bot test Ubuntu16.04 Release_default Build please

# Conflicts:
#	src/fsharp/FSharp.Core/prim-types.fs
@cartermp
Copy link
Contributor

cartermp commented Jun 4, 2018

@dsyme can you re-review this? We have until Tuesday afternoon, then we will make the cutoff for dev15.8. I'd love to get this in for that.

@TIHan TIHan merged commit eb0be3f into dotnet:master Jun 5, 2018
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
* optimize completion

* cache UnresolvedSymbol

do not generalize suppressed types twice

* more cancellable completion provider

* don't call isAttribute twice

remove cancellation from CompletionProvider

* optimize IsExplicitlySuppressed, traverseMemberFunctionAndValues

* cache ILTypeDef.CustomAttrs

* optimize IsExplicitlySuppressed

* avoid using Lazy to store custom attributes in ILTypeDef

* CompletionProvider item's cache: replace dictionary with array

* provide fast generic comparer for bool values

* make getKindPriority inline

* more defensive unresolvedSymbol

* empty array singleton table

* faster IsOperatorName

* optimize CompletionProvider

* Revert "empty array singleton table"

This reverts commit c4ef4ad.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants