Is there a maximum depth for F# inlined functions?

While optimizing at a very busy inner loop -- working on hundreds of millions of floating point numbers -- I used F#'s inline to great effect, partly for type genericity, and partly for performance.

By looking at the decompiled IL, it appears that the F# compiler will only inline to a particular depth (perhaps 3 or 4?). If I write my inner loop by hand (two nested for loops), I get a the loop with expected conversion code inlined. If instead I write a helper function for the loop so that I can parameterize over word size in the data, the loop contains nested function calls instead, even though all the relevant functions are marked inline . This is good for a 2x drop in performance.

I appreciate the inline keyword is meant primarily for static type constraints, not performance enhancement, but this behavior surprised me. Is there a maximum amount of work the F# compiler will do to generate inline IL before it gives up? Is there a way to affect this maximum?

(Looking in detail at the code, one should argue that the CLR JIT itself should be inlining the functions, as they are extremely small, mostly some bit shifting and equality tests, but that's another topic entirely.)

链接地址: http://www.djcxy.com/p/80660.html

上一篇: 在FSharp.Core中未记录`when'关键字的使用情况

下一篇: F#内联函数的最大深度是多少?