JSON: library support and speed and associations

When writing server code within an API request its also important to recognize the tasks, which are taking pretty long. One of the tasks, which are very time consuming is the creation of JSON and the deserialisation of JSON structure. Pretty often the creation of the JSON response structure takes more time than the base…

When writing server code within an API request its also important to recognize the tasks, which are taking pretty long.

One of the tasks, which are very time consuming is the creation of JSON and the deserialisation of JSON structure. Pretty often the creation of the JSON response structure takes more time than the base internal database structure work to find out the result.

So I looked at NeoJSON and introduces some subclasses and by writing a special Gemstone version of the NeoJSONReader one can improve the speed by around 30%. I have not looked yet at the serialize path (NeoJSONWrite) … which is more important and produces bigger structures. To get this speed improvement you have to check all methods sent – especially the ifTrue:ifFalse statement and increase the error handling by using exception all over the place.

The 30% speed improvement could be used to work on a special feature I really would like to see in NeoJSON and lots of libraries (also in other languages) do not support these features.

Consider a 1:n association, but the n part points to the root of a subtree within the class hierarchy. So the collection may contain pretty different instances. Normally JSON libraries might deserialize to the root instance … or they simply return dictionary structures.

I’ve seen this often in Javascript libraries (after all its just JSON) and the programming of such stuff is a nightmare.

The technical solution very often would be to add a technical attribute in your domain model, delivering a hint of the object type represented here (as a string). A mapping from that type string to a full language specific Class should be done (by the JSON library) and so you get very nice, fully object oriented associations.

For fully typed languages, may create an association with a specific interface … just enough to query the type.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.