haskell / haskell/aeson

Compiling a generic ToJSON with stack build --profile consumes much more memory

Open
#810 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
1.3k
Forks
336
Avg merge
3d 7h
Merged PRs (30d)
4

Description

This may be more of a question than it is an issue per se, but I've noticed that compiling a `genericToEncoding` for a timid-enough datatype:

```haskell
data A = A [Int] [(Int, ((String, (Int, Int)), [(Int, Int)]))] deriving Generic
instance ToJSON A where
toEncoding = genericToEncoding defaultOptions
```

- `stack build` takes 288MB
- `stack build --profile` takes 2264MB, which seems like quite a lot.

Progressively simpler datatypes take less and less memory, with `data A = A Int` taking 342MB with profiling and 218MB without. This is with:

- Aeson 1.4.7.1
- Stack version 2.3.1

The project I benchmarked is available at [this repo](https://github.com/acrylic-origami/aeson-issue-2020-09-04-0). See [no-]profile[-simple] files for the memory profiling.

Again, not sure if this is more to do with GHC's treatment of profiling, Stack's `--profile` option, aeson, or GHC generics. I'm also not sure how justified this expectation of lower memory consumption is. I'm personally interested in this because of a cost center profiling tool I'm making, but imagined others had run into these issues trying to profile some Aeson-dependent project as well.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.