[Haskell-cafe] How to speedup generically parsing sum types?

2011-11-03 Thread Bas van Dijk
Hello, I recently added default generic implementations of toJSON and parseJSON to the aeson package. Now I'm optimizing them. Here are some benchmark results that compare: * th: toJSON and fromJSON generated by template-haskell. Can be compared to hand-written code. Should be the fastest of

Re: [Haskell-cafe] How to speedup generically parsing sum types?

2011-11-03 Thread José Pedro Magalhães
Hi Bas, First of all, thanks for these numbers. I have previously compared the performance of GP libs [1] and your results confirm what I would expect, except for that last one, BigSum/fromJSON/generic. It's good that you're using INLINE pragmas on the generic function already. What I would also

Re: [Haskell-cafe] How to speedup generically parsing sum types?

2011-11-03 Thread Bas van Dijk
2011/11/3 José Pedro Magalhães j...@cs.uu.nl: - Compile with -O2 and -fno-spec-constr-count (this last one is particularly important) I already compiled with -O2. Adding -fno-spec-constr-count does not change the results. - Add {-# INLINE [1] #-} pragmas to the to/from methods of your Generic

Re: [Haskell-cafe] How to speedup generically parsing sum types?

2011-11-03 Thread Bas van Dijk
For those who find this interesting. Here's the code of the BigSum benchmark with a manual Generic instance with inlined 'from' and 'to': https://gist.github.com/1336426 José, I was thinking about the following idea. Say GHC generates the following instance for BigSum: instance Generic BigSum

Re: [Haskell-cafe] How to speedup generically parsing sum types?

2011-11-03 Thread Claus Reinke
* syb: toJSON and fromJSON from the Data.Aeson.Generic module. Uses the Data type class. .. As can be seen, in most cases the GHC Generics implementation is much faster than SYB and just as fast as TH. I'm impressed by how well GHC optimizes the code! Not that it matters much if you're going

Re: [Haskell-cafe] How to speedup generically parsing sum types?

2011-11-03 Thread Bas van Dijk
2011/11/3 Claus Reinke claus.rei...@talk21.com: Not that it matters much if you're going with other tools, but your SYB code has a long linear chain of type rep comparisons, at every level of the recursive traversals. That is partially inherent in the SYB design (reducing everything to cast),

Re: [Haskell-cafe] How to speedup generically parsing sum types?

2011-11-03 Thread Twan van Laarhoven
On 03/11/11 11:16, Bas van Dijk wrote: ... instance (Constructor c, GFromJSON a, ConsFromJSON a) = GFromSum (C1 c a) where gParseSum (key, value) | key == pack (conName (undefined :: t c a p)) = gParseJSON value | otherwise = notFound $ unpack key {-#

Re: [Haskell-cafe] How to speedup generically parsing sum types?

2011-11-03 Thread Bas van Dijk
On 3 November 2011 17:38, Twan van Laarhoven twa...@gmail.com wrote: Perhaps relying on Attoparsec backtracking for picking out the right alternative from the sum is the problem. You could try it with Maybe: Good idea. I implemented and committed it and the BigSum/fromJSON/generic benchmark