Skip to content

Generically-like instances are much slower to compile since 2.0.0.0 #1053

@amesgen

Description

@amesgen

Consider deriving e.g. FromJSON via Generically or CustomJSON from deriving-aeson (see fumieval/deriving-aeson#16 for the upstream issue). This is currently very slow for large-ish types, e.g.

{-# 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? 🤔

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions