`Generically`-like instances are much slower to compile since 2.0.0.0
- Dominant language
- Haskell
- Stars
- 1.3k
- Forks
- 336
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 4
Description
Consider deriving e.g. `FromJSON` via `Generically` or `CustomJSON` from `deriving-aeson` (see https://github.com/fumieval/deriving-aeson/issues/16 for the upstream issue). This is currently very slow for large-ish types, e.g.
```haskell
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Aeson
import GHC.Generics (Generic (..))
-- 30 empty constructors
data X = X1 | X2 | X3 | X4 | X5 | X6 | X7 | X8 | X9 | X10 | X11 | X12 | X13 | X14 | X15 | X16 | X17 | X18 | X19 | X20 | X21 | X22 | X23 | X24 | X25 | X26 | X27 | X28 | X29 | X30
deriving stock (Generic)
deriving (FromJSON) via Genericallyish X
newtype Genericallyish a = Genericallyish a
instance (Generic a, GFromJSON Zero (Rep a)) => FromJSON (Genericallyish a) where
parseJSON value = Genericallyish <$> genericParseJSON defaultOptions value
```
takes ~22s to compile on my machine using 8.10 and 9.2, and still 10s on 9.6.
But bisection reveals that before #846, this snippet actually compiled very fast, in only 2s on my machine with GHC 8.10! The main reason seems to be that much less code is generated, which is the exact opposite of what #846 was about in the first place. Maybe there is a minimal subset that can be reverted? :thinking:
Contributor guide
Research direction
Reproduce the 30-constructor example using GHC 8.10, 9.2, and 9.6, and compare it with the pre-#846 behavior described in the issue. Trace the code generated around genericParseJSON and the GFromJSON path, then inspect #846 for the change that increased compilation time. Done means identifying a minimal change that restores near-pre-#846 compile performance without losing the intended behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100