dotnet / dotnet/fsharp

Difference of compilation time between 13 000 "static member" and 13 000 "let binding"

Open
#13,218 4 comments 2 reactions 0 assignees View on GitHub
Area-Compiler-CodeGen Feature Improvement Theme-Performance
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Hello,

while working on a binding for Fable I encounter a case with a huge number elements to map, around 13 000.

Depending on how I represents those elements the compilation time (when running `dotnet build`) can be really different:

- ~20sec for `static member`
- ~2min30 for `let`

I measured the timing in two ways:

- **Force clean**

1. Delete `bin` and `obj` folders
2. Run `dotnet build`

- **Force save**

1. Add a space to the `Types.fs` file
2. Save the file
3. Run `dotnet build`

*If I don't update the `Types.fs` file, then the compilation is almost instant probably because of/thanks to cache mechanism*

## LetBindings

```fs
namespace Glutinum.IconifyIcons.Mdi

open Fable.Core

module mdi =

[]
let _123Off : string = jsNative

[]
let _123 : string = jsNative

[]
let _1password : string = jsNative

// 13 000 more let bindings...
```

### Force save

- 00:03:28.23
- 00:02:35.74
- 00:02:39.66
- 00:02:31.04
- 00:02:28.58

### Force clean

- 00:02:59.43
- 00:01:50.69

## Static members

```fs
namespace Glutinum.strings.Mdi

open Fable.Core

[]
type mdi =

[]
static member inline _123Off : string =
jsNative

[]
static member inline _123 : string =
jsNative

[]
static member inline _1password : string =
jsNative

// 13 000 more static members...
```

### Force clean

- 00:00:17.95
- 00:00:17.35

### Force save

- 00:01:09.75
- 00:01:13.68
- 00:00:18.41
- 00:00:26.16
- 00:00:28.37

*I don't know why the first 2 times it was that slow, perhaps I had something running on my computer taking too much ressources. I left then in the timing because I didn't want to hide this situation*

**Repro steps**

Here is a zip file containing two projects using both of the representation with 13 000 elements in them.

[reproduction-fsharp-compilation-diff-method-let.zip](https://github.com/dotnet/fsharp/files/8812484/reproduction-fsharp-compilation-diff-method-let.zip)

**Expected behavior**

Compilation time between `static member` or `let binding` should not be that different?
As fast as possible compilation time for both representation.

**Related information**

Provide any related information (optional):

* Operating system: Windows 11
* .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET Core 6.0.203
* Editing Tools (e.g. Visual Studio Version, Visual Studio): VSCode Ionide v6.0.5

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.