f# compiling too slow

前端 未结 3 1212
萌比男神i
萌比男神i 2020-12-05 07:34

I\'m new to f#. I downloaded the Visual Studio 2010 shell and the F# ctp and wrote a small hello world script with the following code

printfn \"Hello World\"         


        
3条回答
  •  醉酒成梦
    2020-12-05 08:36

    Unfortunately there isn't much you can do -- the F# compiler is just slower than the C# compiler. But let me explain why:

    Why the F# compiler is slower than the C# compiler

    First, the F# compiler is written on .NET, the C# compiler is written in C++. While this alone isn't a death sentence to perf, it does make a difference. Second, the C# compiler is 10+ years old. There has been a lot of time to tune and optimize it -- both the compiler itself and the .NET runtime. The .NET JIT engine has been fine-tuned for C#/VB.NET and not F#. Functional programming requires a lot of short-lived objects, which translates to different type of GC behavior.

    But the real reason why the F# compiler is noticeably slower than the C# compiler is because it is doing more work than the C# compiler. In C# you provide all of the type information, which in a way is you doing work for the compiler. F# on the other hand does type inference for you, which while saving you from the burden of annotation does require additional CPU time.

    What you can do

    I recommend you download the Visual Studio 2008 shell and use F# targeting the .NET Framework 2.0. Unless you need something that is in Visual Studio 2010 or CLR 4.0 only, you will be fine on Visual Studio 2008. The F# language functions the exact same. The only difference, IIRC, is in what types certain things compile to. For example, there is a Tuple<_> type built into CLR 4.0, but when targeting CLR 2.0 the tuple type defined in FSharp.Core.dll is used.

    Visual Studio 2010 offers a lot of slick bells and whistles, such as a WPF-based code editor. However, those niceties consume a lot of RAM and in your case it sounds like you can live without them.

提交回复
热议问题