What makes FSharpFunc<> faster than Func<>?

前端 未结 2 438
陌清茗
陌清茗 2020-12-29 23:05

I\'m curious about the performance enhancements that have been made for FSharpFunc<>. Is it the fact that it does not contain multiple delegate so there is no need to lo

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 23:26

    (I think they're now called FSharpFunc rather than FastFunc.)

    It's represented as a type with a single abstract method (Invoke), which I think avoids some of the overheads you get with true delegates. And for multiple curried parameters, it enables you to call with all the parameters 'at once' rather than one-by-one (e.g. so that f x y can be invoked on the CLR as f(x,y) rather than f(x)(y).

    Is there anything else? I don't recall right now. You can check out the source code in prim-types.fs in FSharp.Core in the source distribution that comes with the CTP release.

提交回复
热议问题