[Haskell-cafe] [ANNOUNCE] hashable-generics

Herbert Valerio Riedel hvr at gnu.org
Sun Nov 4 16:25:24 CET 2012

Clark Gaebel <cgaebel at uwaterloo.ca> writes:


> Oh yeah, and if anyone wants to help me figure out why it's 1.3x slower
> than my hand-rolled instances, that would be really helpful.


I've taken a look at the bench/Bench.hs benchmark[1]:

The generated Core looks almost[2] the same as your 'HandRolled'; but
the 1.3x slow-down factor seems to be caused by the way the
'bigGenericRolledDS' CAF is defined in the test-harness: if I define it
explicitly (i.e. just as 'bigHandRolledDS' is defined, and not as an
isomorphic transformation of the 'bigHandRolledDS' value) the benchmark
results in both versions having more or less equal performance as would
be expected.

 [1]: https://github.com/wowus/hashable-generics/blob/master/bench/Bench.hs

 [2]: with the following change, it would look exactly the same (modulo
      alpha renamings):

--8<---------------cut here---------------start------------->8---
--- a/bench/Bench.hs
+++ b/bench/Bench.hs
@@ -18,7 +18,7 @@ data GenericRolled = GR0
     deriving Generic
 instance Hashable HandRolled where
-    hashWithSalt salt HR0       = hashWithSalt salt $ (Left () :: Either () ())
+    hashWithSalt salt HR0       = hashWithSalt salt $ ()
     hashWithSalt salt (HR1 mi)  = hashWithSalt salt $ (Right $ Left mi :: Either () (Either (Maybe Int) ()))
     hashWithSalt salt (HR2 x y) = hashWithSalt salt $ (Right $ Right (x, y) :: Either () (Either () (HandRolled, HandRolled)))
--8<---------------cut here---------------end--------------->8---


More information about the Haskell-Cafe mailing list