Giuseppe Maggiore
Giuseppe Maggiore

Reputation: 2031

Compiling an F# quotation: performance?

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?

thanks :)

Upvotes: 3

Views: 650

Answers (2)

J D
J D

Reputation: 48687

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!!!

Upvotes: 5

kvb
kvb

Reputation: 55185

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.

Upvotes: 1

Related Questions