Details
-
Type:
Wish
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: JRuby 1.1.2
-
Component/s: Extensions
-
Labels:None
Description
This is a request for someone in the community to implement Florian Frank's fast JSON library (http://rubyforge.org/projects/json/) using an equivalent Java library to produce a JRuby-compatible gem. I expect more and more folks are going to be using JSON as a wire format for remote APIs, and JRuby would suffer if we don't have an equivalent to Florian's json gem.
-
- parser_java.rl
- 28/Jan/08 10:21 AM
- 18 kB
- Marco Walther
-
- ParserService.java
- 28/Jan/08 10:21 AM
- 52 kB
- Marco Walther
Activity
I have been looking at the possibility of doing this too. Essentially we want to swap out the C parts of the Ragel code and replace it with Java. This seems like the best and most compatible approach.
Mongrel and Hpricot are good examples of this approach.
Just in case someone else has already started on this, I thought I'd mention that a coworker of mine is almost done with a port of Florian's library. I'll try to get him to put the patch here and see if we can get it pushed upstream.
OK, I'm that coworker of Nick
I've a ragel file (and the generated Java source) for the parser. I've still at least two problems (aside from a very hacked environment
.
- UTF-16 - UTF-8 conversions are not done. ('\uDDDD' in the source -> Java -> JRuby -> ...)
- I still have many failures in the tests. But that could be related to my setup.
I was not planing on releasing the code quite yet, but Nick sent me an email yesterday evening about the movement here. So I'll attach my two files for others to look/play.
- UTF-16 - UTF-8 conversions are not done. ('\uDDDD' in the source -> Java -> JRuby -> ...)
- I still have many failures in the tests. But that could be related to my setup.
The first version of the Ragel file. (I used Ragel 6.0 if that makes a difference.)
Whoa, where did you all suddenly come from? One week ago there were no comments at all here or on Charles' blog, other than mine!
This weekend I finally took the time to work on this project, and I already have a fully working port of the json library. Includes both the Generator and the Parser, and passes all the tests that come bundled with the original library with no changes at all to the ruby part of the library (i.e., a drop-in replacement to json/ext).
It is hosted on: http://rubyforge.org/projects/json-jruby/
No releases yet (I still need to check what would be the best way to package it), but you may want to check the subversion repository.
I love open source.
It sounds as though Daniel and Marco should collaborate on what has been done. Daniel's implementation might need some smithing that Marco could provide, and at the very least it's always nice to have two experts on a given library (in preference to two libraries). And I imagine Marco has learned a valuable lesson about keeping projects secret for too long ![]()
Seriously though, we really appreciate all efforts to help fill this gap, especially given the number of REST-based sites and services that will probably use JSON in the future. I'll be watching this bug for updates until we all decide together the problem is completely solved.
Oh, and I should mention one recommendation regarding packaging: please try to work with Florian to get this released as a platform-specific version of the same gem. Differently-named gems quickly fail to scale because so many other libraries depend on specific names.
I'm around for a long time
(But not so long @JRuby![]()
I'll look at your code. If it works, I'll have no problem using it. I simply started on Friday to look into the json parser because we need a fast one. But I have enough other stuff to do as well![]()
Thanks.
I used this project to learn about JRuby's internals, so on the beginning I was a bit lost (that's also why I didn't announce it before; I first wanted to make sure I was able to work properly with JRuby). I believe I have already ironed out most early mistakes I made, but there sure is still something to learn. ![]()
I still plan to document and explain the most important design differences from the C version and refactor some areas (the GeneratorMethodsLoader feels quite messy), but it should be quite workable right now.
Daniel: that's excellent. I'll defer to you to decide when this bug is resolved (perhaps after there's an installable gem available, ideally as simply a separate platform for Florian's library).
Nick, Marco: it would be great if you guys could have a look and see if the existing code works the way you'd hope for project K.
An update on the project status:
I've released a gem on the project page. It's named json_jruby for now (I've sent an email to Florian; let's see what he says), but once installed it goes just like the original libraries (i.e. require "json", not "json_jruby").
From my tests, after the usual warm-up, the parser's performance is amazingly similar to json-C. The generator is a bit slower, but I plan to investigate that.
By the way, I only targeted JRuby trunk. It works with 1.1rc1, but breaks on 1.1b1 (due to RubyHash#visitAll, it seems). If you think some particular version is worth targeting for, please mention it, I can take a look at that.
Nick and Marco, this version should be good enough for testing. Please report anything wrong, or if you need support for a specific JRuby release.
I wouldn't sweat targeting it for anything other than trunk at the moment. We'll get another 1.1 RC out soon, so it's a good way to go.
I'm definitely looking forward to hearing from Nick and Marco.
RC1 and trunk should be fine to target. Ultimately only 1.1 final people will be using this soon.
I was the one who first asked about a JRuby port, I'll be happy to do some testing. I already have a few test suites for two different projects that I was using to test performance of the ActiveResource JSON implementation in Rails 2, and Florian's JSON gem. The tests involve serializing and de-serializing basic ActiveRecord models, so the JSON isn't that complicated.
I'll add comments to this issue if I find any problems.
Where is the gem? I scoured the JRuby project page and wiki, and the jruby-extras and json projects at RubyForge, couldn't find it.
It's on the "JSON-JRuby" (not a very creative name) project:
http://rubyforge.org/projects/json-jruby/
I'm going to mark this fixed, since the json-jruby gem has been out for a while. Hopefully it will get integrated into the native gem, so there's a single place to install from, but this is a solved problem now.
fastjson 1.1.2 is fast!
the benchmark test results:
------------------------
serialize deserialize size compressed size
java serialize 8654 43787 889 541
hessian 6725 10460 501 313
protobuf 2964 1745 239 149
thrift 3177 1949 349 197
avro 3520 1948 221 133
json-lib 45788 149741 485 263
jackson 3052 4161 503 271
fastjson 2595 1472 468 251
----------------------
How to get it?
If you're Maven user, just use our maven repository(http://code.alibabatech.com/mvn/releases/) with folloging dependency
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.2</version>
</dependency>
Downlaods
Binary : http://code.alibabatech.com/mvn/releases/com/alibaba/fastjson/1.1.2/fastjson-1.1.2.jar
Source :http://code.alibabatech.com/mvn/releases/com/alibaba/fastjson/1.1.2/fastjson-1.1.2-sources.jar
Subversion : http://code.alibabatech.com/svn/fastjson/trunk/fastjson/
I'd like to work on this one. But are you saying you want an interface identical to Frank's lib, or are you just looking for "a" JSON lib?