[web-devel] Issues with aeson encoding performance

Chris Smith cdsmith at gmail.com
Mon Aug 29 17:08:41 CEST 2011

I know a lot of you use aeson for JSON encoding, and I get the feeling
I'm doing something wrong here, so if you can give me some kind of a
hint, I'd appreciate it.

The aeson package description talks about getting up to around 40K
messages per second from the encoding, but I'm pegging the CPU at 100%
just trying to send 10 messages per second.  Profiling (which is a REAL
pain to reproduce, since the GHC API is involved... but I locally
butchered a copy of the code enough to route around that) shows JSON
serialization taking 98% of the CPU and doing 99.8% of allocations (on
the order of 5 GB of total allocation if I leave it running for 15
seconds).  Heap profiling also shows the vast majority of the heap
occupied by aeson's types (Value, Number, etc), and with huge spikes.

The streaming code -- very straightforward; it just repeatedly does a
toJSON (getValue (f t)) at most once every 0.1 seconds -- is at


and the serialization (of Gloss's Picture data type) is at


The code to build the Picture data type is the "animation" function in
the second example at:


Any ideas?  I'm about to try rewriting the JSON serialization to avoid
aeson, but before I go there, I thought I'd ask if anyone sees something
obviously wrong here.

Chris Smith

More information about the web-devel mailing list