generics-sop icon indicating copy to clipboard operation
generics-sop copied to clipboard

Improve performance with inlining trick?

Open mikeplus64 opened this issue 7 years ago • 3 comments

*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.

mikeplus64 avatar Aug 23 '18 04:08 mikeplus64

TBD minimal amount of Thingy classes necessary to actually do this :-)

mikeplus64 avatar Aug 23 '18 04:08 mikeplus64

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.

kosmikus avatar Aug 23 '18 06:08 kosmikus

I've just opened #148, which might provide the solution to the compilation times problems.

ghost avatar Dec 20 '21 00:12 ghost