-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced crack parser with the json gem for improved reliability and …
…performance
- Loading branch information
Showing
3 changed files
with
10 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7f2272c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this. Did you consider Yajl too? Reputedly it's faster..
7f2272c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this change to resolve issue #11, not with performance in mind. If you submit a patch swapping in Yajl (including performance benchmarks showing that it's actually faster) I'm sure it would be merged upstream.
7f2272c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind. I got to it first: http://github.com/sferik/twitter/commit/1f480a85925025aec1ac5c91cfb45b4e74e4c9c3
7f2272c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, it's nearly 2x faster than Marshal in some cases: http://gist.github.com/296828
It also has much nicer unicode support (thanks to Yajl itself), and even sets the encoding on all strings returned to the caller to UTF-8 (as valid JSON specifies). It's able to parse stand-alone JSON tokens such as true, false, null, numbers, strings, etc without the need to be wrapped in {} or []. Multiple JSON tokens can exist in the stream/string being parsed, and will be yielded to an optional block passed to the parse method.
Meaning if you were to hand this string (including newlines) over to yajl-ruby:
It would yield 3 objects, the first a ruby hash, the 2nd a ruby array, the 3rd a TrueClass.
This is the basis of many Twitter streaming API gems, as well as libraries using CouchDB's _changes API both which stream multiple JSON tokens over time to the consumer. The encoder can work similarly, the readme should have enough info to get started.
Also, yajl-ruby is now the default/prefered JSON backend in Rails 2.3 and 3.0
btw - a looooong time ago I forked this gem and ported it over to yajl-ruby, sent a pull request to no avail ;)