By looking at the source in FSharp.Core and PowerPack, I think that many high-order functions that accept the function Use two or more parameters for example:
Let's copy f (arr: ResizeArray & lt; _ & gt;) = f f = FSharpFunc & lt; _, _, _ & Gt; ResizeArray & lt; _ & Gt; (Len) i = 0 to do lane - 1 do res.Add (f.Invoke (i, arr [i])) res FSharpFunc.Adapt is quite thin. Is this a normal best practice that any one of our time should use a high-order function with a similar signature? Only if passage-time is called many times? How much is this optimization? <<>
It's quite interesting! I do not have any official information (and I have not seen it documented anywhere), but here are some ideas how the Adapt function can work. Code> mapi function, which means that the type of argument is FSharpFunc & lt; Int, FSharpFunc & lt; T, R & gt; & Gt; Something like . However, many tasks are actually compiled directly into the functions of two arguments, so the actual value is usually FSharpFunc & lt; Int, T, R & gt; which will be FSharpFunc & lt; Int, FSharpFunc & lt; T, R & gt; & Gt; . If you call this function (such as f1 "a" ) the # compiler generates something like this: FSharpFunc & lt; Int, string & gt; Invokefast & lt; A & gt; (F, 1, "A"); If you see the incognition function using reflector, you will see that it tests the customized version ( f:? FSharpFunc & Lt; int, t, r & gt; ). If yes, then invite it directly (1, "A") and if not, then it is necessary to call two calls; code (1). Translation ("a") . This check is done every time when you call the function passed as an argument (it may be faster to check and then use the customized call, because it is more common) . > What is the ediettext function that it does not have any function called FSharpFunc & lt; T1, T2, R & gt; (if the function is not favorable, creates a wrapper for it, but it is not in most of the time). Calls for optimized work will be faster, because they do not need to do dynamic check every time (check is done only once under Adapt ). Therefore, the summary is that optimization can improve performance if you are calling the function passed as a logic, more than 1 logic repeatedly Takes. As with any adaptation, I do not blindly use this, but it is an interesting thing to know about performance tuning! (BTW: Thanks for a very interesting question, I did not know that the compiler does this: -))
Comments
Post a Comment