tags:

views:

120

answers:

2

Hi! I have an F# quotation that I manipulate (I add object pools everywhere to recycle short lived objects that get created and deleted very often). I would like to run the resulting quotation; for now I have used the F# PowerPack which offers methods to convert a quotation to an expression tree and the to a delegate, which I run. Having no access to the generated code, I was wondering:

-what is the performance of the compiled code? Is there some layer of reflection that is not removed or is it a true compilation?

  • can I see the generated code and use .Net Reflector on it?

thanks :)

+1  A: 

This is a bit of a non-answer, but when it comes to performance only you can know what your true performance requirements are. Do you have a particular target running time in mind? Have you tried running the compiled quotation? Was it fast enough? Did you compare it to a natively written F# function?

Regarding your last question, I don't know of any easy way to view an in-memory assembly in Reflector. However, the F# PowerPack's source is available, so you can read it to see exactly how the quotations are compiled.

kvb
+2  A: 

Last I looked, the performance was absolutely awful, around 50× slower than F# and even slower than a naive interpreter.

Frankly, I don't understand why they didn't just expose the F# compiler itself as a run-time service (and FSI). F# would have much better tooling now if they had done...

EDIT: I benchmarked quotations running a fibonacci function last night and it was actually 700× slower!!!

Jon Harrop
Yes, in the end performance was so bad that I wrote my own quotation-to-source function and I compiled that. I agree with you, F# has amazing metaprogramming capabilities which need decent compiling/running facilities to seriously express their potential.
Giuseppe Maggiore
@Giuseppe Maggiore: Yes and the problem goes beyond "compiling/running" into parsing, a domain where F# should excel but currently sucks because of incomplete tools with no IDE support and the non-existence of anything more advanced like on-line parser generators due to that same lack of run-time execution.
Jon Harrop
@Giuseppe Maggiore: FWIW, I've had good results simply compiling directly to CIL for on-the-fly execution instead of using quotations.
Jon Harrop