Game Project: Weekly Recap #2

Progress was slow this week due to the day job using Node.js to write a specialized web server.

Last week I looked at different C/C++ JSON parsing and construction solutions for serialization.  After initially choosing Jansson I found faster, more efficient solutions.   Jansson is a fully-featured and solid API, but like yajl allocates memory a little too often for my taste.

For example, when unserializing JSON from a text buffer, a traditional JSON parser will construct a JSON parse tree of keys and values by duplicating string segments from the source buffer.   After parsing completes, you'll have both the original text buffer and a copy via the generated parse tree.   So if you're source buffer was 1MB, Jansson would allocate both 1MB of string data plus  nodes for the parse tree.

If you don't care about preserving the source buffer, then it should be possible to tokenize the original buffer and have your parse tree's string pointers reference those tokens.   Fortunately there are solutions that do just that. 

I eventually chose RapidJSON, a fast and efficient C++ based solution.  There are others (vJSON, Sajson, and jsmn), but RapidJSON was the most adopted and best documented library out there for the task.  And I've spent a bit too much time analyzing JSON libraries…