-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generically
-like instances are much slower to compile since 2.0.0.0
#1053
Comments
It doesn't seem to be a problem with #846. On my machine, with GHC-9.6.2 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 Generically X takes 15s to compile, but instance FromJSON X where
parseJSON = genericParseJSON defaultOptions just 2.5 Why |
What leads you to that conclusion? As said above, I found this via bisecting, i.e. we have
and the snippet I posted above compiles quickly on b9c635e (pre-#846), but slowly on b5f12d2 (the commit from #846). This seems to be a very strong indicator to me that it is the reason for the slowdown, or am I missing something here? Indeed, it is interesting that this does not seem to be a problem with the |
Let's be clear: Reverting #846 is out of question. The #846 however added That said, E.g. in your example And even than, So TL;DR, |
Sure, wasn't suggesting fully reverting #846; but there still might be a minimal subset that can be reverted that fixes this issue, but does not cause compile-time increases in other areas. I will play around with it a bit, but one potential outcome indeed is " |
Came here with a very slow/high memory compilation of the type with ~24 constructors... Moving to TH is not trivial for us too, as we are using a forked version because of that: #926 Questions:
|
Not really. I don't like the swiss-knife approach current Generic framework uses, and adding more options makes its maintenance even worse. #933 will solve that, but I don't know when I'll have time and motivation to do that. #933 will probably solve this issue too, because simple |
I am usually also against adding options, but the current default simply makes no sense - you get objects for all other constructors and an empty array for an empty one, and where it is needed it simply doesn't work... The only reason I suggested it as an option was to avoid breaking changes - but would you maybe prefer making it a breaking change? I can't see the use case where the current default is useful, tbh. |
No. Breaking change which doesn't cause compiler to scream is a worst possible for the users. The majority of people will be surprised. It's also not a choice.
And from Prelude GHC.Generics> data Foo = Foo deriving Generic
Prelude GHC.Generics> data Bar = Bar {} deriving Generic
Prelude GHC.Generics> :kind! Rep Foo
Rep Foo :: * -> *
= M1
D
(MetaData "Foo" "Ghci2" "interactive" False)
(M1 C (MetaCons "Foo" PrefixI False) U1)
Prelude GHC.Generics> :kind! Rep Bar
Rep Bar :: * -> *
= M1
D
(MetaData "Bar" "Ghci3" "interactive" False)
(M1 C (MetaCons "Bar" PrefixI False) U1) Their The current default makes sense. |
Right, but not when you have several record constructors, which is more common in real world, with one empty one among them, and all record constructors are encoded as objects, and the empty one as an empty array... What's worse, it's not something that's easy to fix on the consumer side, as it's not a library. Hence the need to be able to configure it, and it wasn't even difficult. |
Now we have a sum type that takes ~8min and 12gb RAM to compile FromJSON in GHC 9.6.2... Sad times. Any idea if/when it can be resolved? Could we help by sponsoring the solution a bit? Also, the same question re #926 - any chance we can sponsor it? As the current SingleFieldObject isn't compatible with the main environment that uses it... |
You can contact my employer for options. Though I will hesitate to promise anything concrete. At best, you can have your own deriving which is tailored for your needs, i.e. is fast and does exactly what you need and not more. That's a direction I'd like to move |
Thank you!
And here I was hoping it's somebody's individual project :) In any case, moving just couple of types to TH improved compilation time and memory a lot - any known issues with it? Also, any chance we could support nullaryToObject (#933)? The current default is not usable with Swift, unfortunately. Also, any pointers where it would fit in TH - a quick glance through the code didn't suggest an obvious way to add it, so just added |
Consider deriving e.g.
FromJSON
viaGenerically
orCustomJSON
fromderiving-aeson
(see fumieval/deriving-aeson#16 for the upstream issue). This is currently very slow for large-ish types, e.g.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? 🤔
The text was updated successfully, but these errors were encountered: