Friday, September 14, 2012

Faster Printf Released on NuGet

EDIT: The project described in this article is in alpha stage. If you are interested in a more mature an faster drop-in replacement for F# Printf module, check out Arseny Kapoulkine's fastprintf.

There is news on the faster F# Printf.* story. We released an alternative implementation as a package today.

NuGet: IntelliFactory.Printf


Some background: F# Printf.* functions are a very nice interface for formatted printing, but the default implementation is quite slow, which is undesirable for production use (say, for logging inside a server). I believe the F# team is addressing this for their next release - and when it comes, it is going to be awesome. In the meanwhile, we offer a drop-in replacement library that can speed things up a bit with the existing F#.

The code does not go the full 100% way of what is possible to optimize, in particular it does not use Reflection.Emit to attempt constructing an efficient closure capable of bypassing some of the closure allocation overhead via FastInvoke. However, I believe the improved performance already is practical, and the part of the implementation dealing with closure construction is pleasantly clear and easy to understand this way.

If you decide to try it out, note that this is an alpha release as it does not yet support format modifier flags and %A yet (I intend to rectify this as time permits).

ACKNOWLEDGEMENTS: I would like to thank Vladimir Matveev from the Microsoft F# team for some fruitful discussions on the internals of F# Printf.*; This project is largely based on my best attempt to beat Vladimir's code on a set of micro-benchmarks. In the end I lost the race, as Vladimir has come up with an even faster implementation since then. I am still quite happy though, knowing that with any luck Vladimir's code will make it to the F# trunk, and all will benefit.