Catch errors thrown from pure computations using primops. https://github.com/michaeljklein/prim-spoon
|Latest on Hackage:||0.1.0|
This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.
This is a microproject for the sole purpose of having a high-performance
teaspoon from Control.Spoon, using primops.
While it is unsafe, it is as safe as
seq# from GHC.Prim.
(I’d look into how safe those are, but they’re hidden in GHC’s source and that really seems like overkill.)
primspoon takes about 3x as long as a function call on non-error
throwing values and about 5x as long to catch an error and return
This is an improvment over
teaspoon, which takes about 4x as long as a
function call on a non-error value and about 21x to catch an error.
Why bother? Three reasons:
- This is my first experience with digging into primops in Haskell for performance, and it was a good exercise.
- I had begun to roll my own solution before I found
Control.Spoonand wanted to benchmark several different solutions (for example,
- I was curious how
unsafePerformIOaffects performance. It turns out that it takes longer than I expected, but it makes some sense as it’s not the best thing to spend time optimizing.