fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
770 stars 191 forks source link

Immutable arrays #2884

Closed nojaf closed 1 year ago

nojaf commented 1 year ago

In light of recent talk about immutable arrays in FSharp.Core and the compiler, I wanted to get a sense of whether we would benefit from them in Fantomas.

And I also wanted to challenge the proposal for having them as first-class citizens in the language. As in, do we really need a special syntax for them, while a computation expression might also just fit the bill?

My initial thoughts on this are that we don't need it here in Fantomas. The benchmark improvement is rather limited. Which might just indicate that this was the wrong project to test out. From a code perspective, I'm actually pretty ok with the computation expression. It is not perfect but decent enough.

Before:

BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22621.1702)
12th Gen Intel Core i7-12700K, 1 CPU, 20 logical and 12 physical cores
.NET SDK=7.0.400-preview.23272.51
  [Host]     : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2 DEBUG
  DefaultJob : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2

| Method |     Mean |    Error |   StdDev | Rank |     Gen0 |     Gen1 | Allocated |
|------- |---------:|---------:|---------:|-----:|---------:|---------:|----------:|
| Format | 96.15 ms | 0.496 ms | 0.440 ms |    1 | 500.0000 | 333.3333 | 154.81 MB |

After:

BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22621.1702)
12th Gen Intel Core i7-12700K, 1 CPU, 20 logical and 12 physical cores
.NET SDK=7.0.400-preview.23272.51
  [Host]     : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2 DEBUG
  DefaultJob : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2

| Method |     Mean |    Error |   StdDev | Rank |     Gen0 |     Gen1 | Allocated |
|------- |---------:|---------:|---------:|-----:|---------:|---------:|----------:|
| Format | 92.49 ms | 0.913 ms | 0.854 ms |    1 | 500.0000 | 333.3333 | 148.35 MB |