generics-sop
generics-sop copied to clipboard
Improve performance with inlining trick?
*traverse*, *cata*, *pure*, etc. can all potentially be implemented using recursive class instances like
class Thing xs where thing :: thing xs
instance Thing '[] where {-# INLINE thing #-} thing = _
instance Thing (x ': xs) where {-# INLINE thing #-} thing = _
which would allow them to be zero overhead, and, hopefully, for GHC to be able to eliminate generics-sop overheads entirely. I'm not sure whether sList has the effect of tricking GHC into doing this already but that does seem possible.
Cons: yet longer compile times, yet more dictionaries to pass around.
TBD minimal amount of Thingy classes necessary to actually do this :-)
I know.
This is implemented in https://github.com/well-typed/generics-sop/tree/wip/static-case-opt
Unfortunately, in my tests so far, this often increases compilation time and only very unreliably improves performance, as it is difficult to get GHC's inliner to be sufficiently aggressive without any negative side effects. So while this branch exists for several years, I haven't ever merged it.
More recently, I've also experimented with stream fusion in https://github.com/well-typed/generics-sop/tree/wip/stream-fusion This is not yet quite done, so I cannot tell yet whether it might work.
I've just opened #148, which might provide the solution to the compilation times problems.