GWT 2.1 has reached Milestone 2.
One of the new features in version 2.1 is support for browser’s native JSON function in
Now there are three methods JSONParser which may be used to parse JSON string:
JSONParser.parseNative(String)- Uses native JSON browser’s function, if browser supports it
JSONParser.parseLanient(String)- Uses browser’s eval() function
JSONParser.parse(String)- Old method that is still supported and actually calls
Under Google Chrome
parseNative() works usually 30-50% faster than
parseLanient(): 450 vs 800 ms for parsing json string 10000 times.
Chrome Native JSON Test: ------------------------ JSON src length=3467 chars; 10000 iterations. Native JSON time: 1692ms Parser Native JSON time: 1728ms Parser Lanient JSON time: 853ms
Under Firefox, results are different from time to time (from 80 to 200ms). Native function may be 2 times faster or 2 times slower. So it seems there will be no significant speedup using native under Firefox.
But anyway, Firefox has faster evaluate json than Chrome.
Firefox Native JSON Test: ------------------------- JSON src length=3467 chars; 10000 iterations. Native JSON time: 1224ms Parser Native JSON time: 1208ms Parser Lanient JSON time: 974ms
Using new function has sense for browser like Chrome where performance can be improved.
P.S. All measurements are valid on June 2010