

Fast, auto-generated streaming JSON parsing for Android - mikeyk
http://instagram-engineering.tumblr.com/post/97147584853/json-parsing

======
swanson
Cool - if this is indeed faster than Jackson (and GSON), I would recommend
writing a Retrofit converter
([https://github.com/square/retrofit/tree/master/retrofit-
conv...](https://github.com/square/retrofit/tree/master/retrofit-converters))
so developers can just drop in ig-json-parser for use with Retrofit.

~~~
tonytung
This is based on Jackson stream parsing, so by definition, it can't be faster
than Jackson. :)

------
jc4p
This looks cool, but I'm also interested in seeing if compared to GSON not
just Jackson. Is the `JsonField` annotation mandatory? In most cases my
variable names are the same as the field names in the JSON, which is why I
love using GSON since it auto-picks up on that.

It looks kind of odd in your sample code too, it'd be nice if it could auto-
try those fields, but I can see why that won't work if this is compile-time
rather than at processing-time like GSON (it has no way of checking against
the JSON to see if that assumption is true) -- maybe have `JsonType` take and
optional parameter that enables "guess types" mode?

~~~
tonytung
Hi!

I'm one of the authors of this library. The code this library emits is very
similar to the json/jackson/manual serializer/deserializer in
[https://github.com/eishay/jvm-
serializers/wiki](https://github.com/eishay/jvm-serializers/wiki).
Conveniently, GSON is benchmarked there too.

You're right, the field names could be guessed at compile time. Please feel
free to submit a PR!

Thanks!

------
azinman2
And look at how slow it still is. 40ms to parse json? I can do that around or
under 1ms in iOS. When porting our app to android this was one of the biggest
unexpected bottlenecks that really impacts performance. I don't know why
android doesn't provide a native json implementation to reduce this barrier to
entry.

~~~
gsoltis
Surely the size of the JSON payload matters for this benchmark. Just saying
you can parse json in under 1 ms is somewhat meaningless unless you're
comparing similar sized json documents, as well as marshalling into a user-
supplied class.

~~~
azinman2
And that's exactly what I'm comparing. This was the shock that came from the
same data being loaded into android as ios being over an order of magnitude
slower.

~~~
gsoltis
Interesting. What are you using for object marshalling on iOS? And which json
processor are you using on your android benchmark? The referenced library?

~~~
azinman2
Jackson (best performing) vs JSONKit. But Apple's is close enough as well.

------
gnewton77
I've added an issue to chidley to generate these classes, in addition to the
Java/JAXB classes it produces now:
[https://github.com/gnewton/chidley/issues/4](https://github.com/gnewton/chidley/issues/4)

(Of course only for json generation from XML)

------
dozy
How does this compare to loading up a String of json in an org.json.JSONObject
and parsing it manually?

For some further abstraction/encapsulation, you can extend the JSONObject
class and provide getters/settings for particular key/values.

~~~
tonytung
The two are not really comparable since you get different results (JSONObjects
are not strongly typed). You will easily be able to find workloads where one
is better than the other, but in the average case, ig-json-parser will
probably be faster because it's based on Jackson. (see json/jackson/manual vs
json/org.json/manual on [https://github.com/eishay/jvm-
serializers/wiki](https://github.com/eishay/jvm-serializers/wiki))

------
nellyspageli
How does this compare to GSON?

~~~
tonytung
Please see the comment here
[https://news.ycombinator.com/item?id=8298557](https://news.ycombinator.com/item?id=8298557)

