You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for i in[0..10000000]do// 3194ms (yikes!)
last <- i
for i in0..10000000do// 3ms
last <- i
for i =0to10000000do// 3ms
last <- i
for i inseq{0..10000000}do// 709ms (smaller yikes!)
last <- i
non-integer for loops, and loops with non-1 steps are also a problem for the same reason: for i in 0.0f .. 1000000.0f for i in 0 .. 2 .. intForLoopIterations
for i in [0 .. 10000000] do is really a black hole because (A) it allocates a full 10M-element list, then (B) walks it using IEnumerable. #219 addresses part (B) at least.
I'm tempted to blame the user for part (A) - they asked for a list, so they got a list... That's why the for i in 1 .. 10000000 do syntax is there. Do developers not realize [a .. b] creates a list?
@braden yes, there are a bunch of gaps there, which might represent relatively low-hanging fruit for anyone interested in codegen optimizations.
yes, a list is a list 😄 but is an easy target for an optimization.
The real gold here is the walkthrough, is really good, can be a base guide for multiple similar optimizations.
I cannot find the github account of user fulesnabel, a shame
Yes it was me that wrote that SO post. I am actually working the SO post into something of a blog post explaining (hopefully) how to do a expression optimization. The blog post will contain functionality and IL generation tests as well. The plan is to end the blog post by posting it as a PR to F# (with the possibility it gets rejected which is also a good learning ;))
@mrange please do it
the post will become a really good intro on FSharp compiler, i really liked the style
I was going to ask you about a pr on SO , but thx latkin 😄
The SO post was skimped over how to do testing which I included in the blog. That of course made it bigger. @sergey_tihon has some feedback where he was asking for a better introduction so I tried to address that to.
Activity
braden commentedon Apr 22, 2015
non-integer for loops, and loops with non-1 steps are also a problem for the same reason:
for i in 0.0f .. 1000000.0ffor i in 0 .. 2 .. intForLoopIterationslatkin commentedon Apr 22, 2015
for i in [0 .. 10000000] dois really a black hole because (A) it allocates a full 10M-element list, then (B) walks it usingIEnumerable. #219 addresses part (B) at least.I'm tempted to blame the user for part (A) - they asked for a list, so they got a list... That's why the
for i in 1 .. 10000000 dosyntax is there. Do developers not realize[a .. b]creates a list?@braden yes, there are a bunch of gaps there, which might represent relatively low-hanging fruit for anyone interested in codegen optimizations.
enricosada commentedon Apr 22, 2015
yes, a list is a list 😄 but is an easy target for an optimization.
The real gold here is the walkthrough, is really good, can be a base guide for multiple similar optimizations.
I cannot find the github account of user fulesnabel, a shame
latkin commentedon Apr 22, 2015
Agreed, great walkthrough. User's profile mentions T4, I wonder if it is @mrange?
mrange commentedon Apr 22, 2015
Yes it was me that wrote that SO post. I am actually working the SO post into something of a blog post explaining (hopefully) how to do a expression optimization. The blog post will contain functionality and IL generation tests as well. The plan is to end the blog post by posting it as a PR to F# (with the possibility it gets rejected which is also a good learning ;))
mrange commentedon Apr 22, 2015
WRT to
for i in 0.0f .. 1000000.0f,for i in 0 .. 2 .. intForLoopIterationswhen looking into this earlier these are more intrusive.IIRC these changes required changes the AST and pickle.fs which always scares me.
enricosada commentedon Apr 22, 2015
@mrange please do it
the post will become a really good intro on FSharp compiler, i really liked the style
I was going to ask you about a pr on SO , but thx latkin 😄
mrange commentedon Apr 22, 2015
In case you are interested in giving feedback on the blog post please see: https://mrange.wordpress.com/?p=706&shareadraft=5536c7f96b8a5
The SO post was skimped over how to do testing which I included in the blog. That of course made it bigger. @sergey_tihon has some feedback where he was asking for a better introduction so I tried to address that to.
enricosada commentedon Apr 23, 2015
@mrange sent feedback! thx