Hm, you're right, the F# compiler is not (yet) smart enough to turn a "foreach" loop over an array into a simple indexing loop. So if you want good perf (to avoid the needless enumerator/disposable-try-finally), use a loop with an index variable on arrays. I've filed a bug against the compiler for this.

By on 11/29/2008 3:30 PM ()

Brian

Thanks for the response. I'm curious where all the consing comes from with the enumerator case.

Bill

Hm, you're right, the F# compiler is not (yet) smart enough to turn a "foreach" loop over an array into a simple indexing loop. So if you want good perf (to avoid the needless enumerator/disposable-try-finally), use a loop with an index variable on arrays. I've filed a bug against the compiler for this.

By on 11/29/2008 6:59 PM ()

Brian

Thanks for the response. I'm curious where all the consing comes from with the enumerator case.

Bill

Hm, you're right, the F# compiler is not

(yet) smart enough to turn a "foreach" loop over an array into a simple

indexing loop. So if you want good perf (to avoid the needless

enumerator/disposable-try-finally), use a loop with an index variable

on arrays. I've filed a bug against the compiler for this.

I'm curious what the code that's being generated is. Take a look at .NET Reflector.

Simply open up NPuzzle.exe, browse down to

NPuzzleP1.NPuzzle.Puzzle.LowerBoundOnScore (or wherever the code in

question is), select C# as the language to display in, and you should

get the exact C# code that the compiler is generating. When I do this

for the two code fragments in question, I get very similar results, with the main source of overhead being the standard overhead from the SzArrayEnumerator.MoveNext() class, which is not much different than your own overhead of incrementing the i index. Still though, I'm not sure if "consing" is really the right word here, I don't see how there's any consing going on at all, since there's no F# lists anywhere.

By the way, the forum does support posting code blocks, just wrap it in code tags ([] brackets, not <> brackets) with a language="F#" attribute.

By on 11/29/2008 10:36 PM ()

Divisor

I believe the GC results clearly establish that there is additional consing going on. (By "consing" I mean heap allocation - of any kind. Those of us who were raised on Lisp and friends tend to use this term in a generic way.) The increase in gen 0 collections indicates a much larger number of short lived objects are being allocated.

In any case I'll take a look at Reflector as I'm sure its results will be instructive.

Regards,

Bill

... Still though, I'm not sure if "consing" is really the right word here, I don't see how there's any consing going on at all, since there's no F# lists anywhere.

By on 11/30/2008 8:12 AM ()

Divisor

I tried using [language=F#] ... [/language], but this didn't seem to work; i.e., the added tags just displayed as text. What have I missed? (I edited my original post -- so take a look to see what I mean.]

Thanks,

Bill

...

By the way, the forum does support posting code blocks, just wrap it in code tags ([] brackets, not <> brackets) with a language="F#" attribute.

By on 11/30/2008 8:04 AM ()

Divisor

I tried using [language=F#] ... [/language], but this didn't seem to work; i.e., the added tags just displayed as text. What have I missed? (I edited my original post -- so take a look to see what I mean.]

It's

[ c o d e l a n g u a g e = " F # " ]

[ / c o d e ]

with spaces removed.

Regarding the other post about consing, I guess it was just a misunderstanding of terminology. I'm accustomed to using it only to refer to the act of appending an element to the head of a list.

By on 11/30/2008 1:50 PM ()

See this thread to learn the syntax highlighting:

[link:cs.hubfs.net]

By on 11/30/2008 10:39 AM ()

Brian

Thanks, I've (re)edited my original post to make the F# code more readable. I also changed the

1
 for i = ...

to a

1
 for j = ...

loop in order to avoid getting emoticon gibberish instead of the bracketed index reference (which resulted when I used "i" as the variable.) Any way to turn off that stuff within a code block?

Finally, are the Community Server BBCodes (or the ones used by hubFS) documented anywhere? I tried the Help link on this page, but no help. Googling didn't help me much either.

Bill

See this thread to learn the syntax highlighting:

[link:cs.hubfs.net]

By on 11/30/2008 12:25 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper