One of the concerns expressed by some of the remaining OCaml users, such as Yaron Minsky of Jane St Capital, is the relative performance of F# in the context of purely functional data structures. Specifically, language implementations like OCaml are heavily optimized for this use case due to their legacy and on-going use for applications such as theorem proving, which benefit greatly from the efficient handling of purely functional data structures. Historically, most users of imperative languages such as Java and C# have not required this kind of performance and, consequently, their implementations have not been optimized for this style of programming. However, the recently released .NET 4 includes a new garbage collector and we have found that it provides substantial performance improvements in the context of purely functional data structures which is of particular benefit to F# developers.
We recently examined the performance of four different purely functional heap implementations across five different benchmarks written in both OCaml and F# (see Data structures: heaps). Where our previous findings in similar benchmarks showed F# to be 5× slower than OCaml, our new results indicate that F# on .NET 4 is now only 2× slower than OCaml on average. In one case, a leftist min heap with elements inserted in descending order, F# even ran 20% faster than OCaml.
This is a surprising and encouraging result not only because it makes F# competitive for an even wider variety of tasks but because it also implies that Microsoft are taking F# so seriously that they are optimizing the .NET garbage collector for it!