Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Issue 10230004: Optimize the JSON parser by tokenizing while parsing and using jump-table. (Closed)

Created:
8 years, 8 months ago by Anders Johnsen
Modified:
8 years, 7 months ago
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Optimize the JSON parser by tokenizing while parsing and using jump-table. I've also updated the test to include a few corner cases. My tests shows a 50-80% speedup. The optimization will also give a lower memory usage since we don't keep a list of all tokens alive. BUG= TEST= Committed: https://code.google.com/p/dart/source/detail?r=7056

Patch Set 1 #

Total comments: 27

Patch Set 2 : Inline and small fixes. #

Total comments: 18

Patch Set 3 : Optimized expectKeyword and privitized JsonParser. #

Patch Set 4 : Pull out a few more constants. #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+338 lines, -396 lines) Patch
M lib/json/json.dart View 1 2 3 3 chunks +288 lines, -396 lines 2 comments Download
M tests/utils/src/JsonTest.dart View 1 1 chunk +50 lines, -0 lines 0 comments Download

Messages

Total messages: 11 (0 generated)
Anders Johnsen
8 years, 8 months ago (2012-04-26 13:30:43 UTC) #1
Anton Muhin
Sorry for popping up, but I wrote the original version. https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart File lib/json/json.dart (right): https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart#newcode31 ...
8 years, 8 months ago (2012-04-26 16:13:20 UTC) #2
Anders Johnsen
Thank you for jumping in! :) Your feedback is always welcome! https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart File lib/json/json.dart (right): ...
8 years, 8 months ago (2012-04-27 05:22:22 UTC) #3
Mads Ager (google)
lgtm https://chromiumcodereview.appspot.com/10230004/diff/5001/lib/json/json.dart File lib/json/json.dart (right): https://chromiumcodereview.appspot.com/10230004/diff/5001/lib/json/json.dart#newcode41 lib/json/json.dart:41: class JsonParser { Do you want this to ...
8 years, 8 months ago (2012-04-27 06:49:29 UTC) #4
ricow1
LGTM, can't wait to see the impact https://chromiumcodereview.appspot.com/10230004/diff/5001/lib/json/json.dart File lib/json/json.dart (right): https://chromiumcodereview.appspot.com/10230004/diff/5001/lib/json/json.dart#newcode86 lib/json/json.dart:86: Add a ...
8 years, 8 months ago (2012-04-27 06:57:31 UTC) #5
Anders Johnsen
Thank you all for the reviews. Committing! https://chromiumcodereview.appspot.com/10230004/diff/5001/lib/json/json.dart File lib/json/json.dart (right): https://chromiumcodereview.appspot.com/10230004/diff/5001/lib/json/json.dart#newcode41 lib/json/json.dart:41: class JsonParser ...
8 years, 8 months ago (2012-04-27 07:07:16 UTC) #6
Lasse Reichstein Nielsen
Drive-by-comment. https://chromiumcodereview.appspot.com/10230004/diff/14001/lib/json/json.dart File lib/json/json.dart (right): https://chromiumcodereview.appspot.com/10230004/diff/14001/lib/json/json.dart#newcode285 lib/json/json.dart:285: } You need to bail out here if ...
8 years, 8 months ago (2012-04-27 07:26:36 UTC) #7
Anders Johnsen
https://chromiumcodereview.appspot.com/10230004/diff/14001/lib/json/json.dart File lib/json/json.dart (right): https://chromiumcodereview.appspot.com/10230004/diff/14001/lib/json/json.dart#newcode285 lib/json/json.dart:285: } On 2012/04/27 07:26:36, Lasse Reichstein Nielsen wrote: > ...
8 years, 8 months ago (2012-04-27 07:32:33 UTC) #8
Anton Muhin
https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart File lib/json/json.dart (right): https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart#newcode31 lib/json/json.dart:31: JSONParseException(int this.position, String message) { Why duplicate type info? ...
8 years, 8 months ago (2012-04-27 16:45:40 UTC) #9
Lasse Reichstein Nielsen
DBC https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart File lib/json/json.dart (right): https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart#newcode32 lib/json/json.dart:32: this.message = "JSONParseException: $message, at offset $position"; It ...
8 years, 7 months ago (2012-04-30 08:12:02 UTC) #10
Anton Muhin
8 years, 7 months ago (2012-05-02 10:07:14 UTC) #11
https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart
File lib/json/json.dart (right):

https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart#new...
lib/json/json.dart:32: this.message = "JSONParseException: $message, at offset
$position";
Lasse, this file used single quotes, not double quotes, hence I asked to follow
this style.

If consensus is double quotes are preferred, that's okay, but I'd ask for a
separate change and for changing all the quotes.

On 2012/04/30 08:12:02, Lasse Reichstein Nielsen wrote:
> It seems it's the most prevalent quoting in Dart, probably taken from the JS
> style guide which prefers ' over ".
>
http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml?showone...
> 
> Personally I write double quotes all the time, and only notice and change them
> if someone else notices. It's just in my fingers from years of C/C++/Java (and
> JavaScript with double-quotes) programming. Single quotes are for characters!
I
> also read them more easily, and don't get hit when writing "isn't" in my
> strings.

https://chromiumcodereview.appspot.com/10230004/diff/1/lib/json/json.dart#new...
lib/json/json.dart:131: int tokenKind = _token();
Again, that's the style in this file.

And I used final's not for performance sake, but for semantics sake: now it's
obvious for the one who reads the code, that this value shouldn't change.

But I was ridiculed for my love to finals in Java as well.

On 2012/04/30 08:12:02, Lasse Reichstein Nielsen wrote:
> final int tokenKind;
> Don't drop the type. (I don't particularly care for making local variables
final
> - seems like overdoing it, any competent compiler should be able to see that
it
> doesn't change anyway).

Powered by Google App Engine
This is Rietveld 408576698