-
Notifications
You must be signed in to change notification settings - Fork 323
Speed up default FromJSON/ToJSON instances #335
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
nice! too much inlining strikes again. What cabal version bump is needed here? |
I'm not sure. This does make an API change (albeit a small one) in that |
For completeness's sake, I went ahead and ran the most relevant benchmark I could find in the
|
Really nice work, @RyanGlScott – thank you! I'm applying this right now. |
Speed up default FromJSON/ToJSON instances
👍 |
Fixes #296 and #309 (I believe).
The
DefaultInstances
-based mechanism for derivingFromJSON
andToJSON
instances via GHC generics currently consumes way more memory than it should. I believe this is the result of two things:GHC Trac #9630. It was discovered that having generic classes that have more than one method such as:
hurt the optimizer badly. To compensate for this bug, I split
GToEncoding
off fromGToJSON
(as well as the many internal typeclasses thatGToJSON
uses).Data.Aeson.Types.Generic
putsINLINE
pragmas on all generic class instance methods. This results in an explosion of inlined code, to the point thatpandoc-types
takes ~7 GB of memory to compile. In my experience, inlining generic methods has turned out to be a bad idea, so I've removed theINLINE
pragmas.To test out the improvments, I did a very fast-and-loose profiling of the time and memory it takes to compile
pandoc-types
(a package known to be affected badly by theaeson-0.10
compilation regressions). I did these tests on a 64-bit Linux laptop with 4 GB of RAM. Here are the results:pandoc-types
(vanillaaeson-0.10
):pandoc-types
(aeson-0.10
with the changes in this pull request):The total wall time went from 10 minutes to under a minute, and it went from using 3 GB of RAM (and thrashing my laptop mercilessly) to about 500 MB of RAM.