Reputation: 1811
I'm trying to find the best way to transfer data from server -> client using Google Web Toolkit (GWT). I have some JSON text I'd like to send, but the 2 options I've used for doing so have both been very slow.
Option 1: Server generates JSON string, parses this into Java objects (a serializable class I've made), sends list of these over RPC, objects then used by client side. The block here is the RPC connection, which is ridiculously slow at transferring & serializing objects.
Option 2: Server generators JSON string, does NO parsing work, RPC's to client as a string, client then parses into Java objects and deals with. The block here is the client side GWT JSON parsing library, which is slow as molasses (~7 seconds for 13 objects).
The only 'fast' option I've tried is one concatenated string of fields created by each instance of the serialized class, which is then split and chopped on the client side. However, this is sloppy and prone to breaking if the splitting character were ever used in the content being transferred.
Maybe I'm doing something totally, obviously wrong. But any knowledge of how to improve GWT JSON parsing times or RPC transfer times would be appreciated!
Cheers,
Paul
Upvotes: 2
Views: 1900
Reputation: 5218
I would recommend using the browser JSON parser, wrapped in a JSNI method. Note that legacy browsers don't support it, so you can use https://github.com/douglascrockford/JSON-js to cover that gap.
Note that the supplied com.google.gwt.json.client JSON methods aren't the fastest in the west, as they use wrapper objects. I've written my own JSON library (to be released as open source before too long), but in the meantime you can just write JSNI methods to traverse the JSON objects at native speed.
Upvotes: 4