
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 https://github.com/cdsmith/gloss-web/blob/master/src/Main.hs#L188 and the serialization (of Gloss's Picture data type) is at https://github.com/cdsmith/gloss-web/blob/master/src/Instances.hs#L106 The code to build the Picture data type is the "animation" function in the second example at: http://cdsmith.wordpress.com/2011/08/20/animations-added-to-web-based-haskel... 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