-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does MultiJson introduce slowness? #113
Conversation
Preamble
Therefore, be it resolved, effective July 2013
@AaronRustad Thank you for creating this benchmark and opening this issue. After doing some additional benchmarking of my own and giving it much thought, I am convinced that the tradeoffs that motivated this library in 2010 are no longer worthwhile in 2013. |
@sferik Thanks for the update. And thanks for your work on this in the past and up until now. |
@sferik wow... Just wow. |
@sferik 👍 |
This test is slightly flawed because it is such a small JSON object, as a result the overhead of initiating the call is exaggerated in the results (compared to most regular use cases). There is still for sure some performance improvements to MultiJSON that can be done. Abandoning the project and moving to the built-in is a valid way to deal with this problem; but there is a lot of libraries that depend on MultiJSON; if this is you taking a stance and telling them to use the built-in and follow suit 👍 otherwise I will start becoming a contributor to see if we can make MultiJSON not have these performance concerns. Best Regards! |
@AlexRiedler For what it’s worth, I modified the benchmarks to dump and load larger chunks of JSON and the overhead was still significant. |
I have unfinished branch with refactoring that improves performance by about 100% in this benchmark. It's not ready yet, but I expect to finish and push it quite soon. |
These are the results of benchmark on my MBA before and after the performance path: before:
after:
|
I'll weigh in on this weighty issue. @sferik first thank you 1000x for all of your hard work on this over the years. I started MultiJson because at the time there were a ton of JSON libraries that were all being used in various projects and I didn't want my own open source to demand that users pick one over another. It was a library for library authors, and that's still how I see it. I can certainly see sense in dropping down to the baked-in default now that One thing I can say: addressing performance concerns is of the utmost priority moving forward with this library. The primary reason that people swap between JSON libraries is for performance, and if MultiJson is negatively impacting that performance than it is defeating the purpose in many ways. So thanks @rwz for starting to address this and I hope that other perf experts will chime in to get the code as optimized as possible. I think to a large extent the longevity of MultiJson depends on how well these performance overhead concerns can be addressed. |
⛳ 👏 @sferik |
Does MultiJson introduce slowness?
I really like how multi_json could ensure you have a working json library across ruby vm's when requiring it as a gem dependency. e.g. metricfu/metric_fu@454b70d |
@mbleigh Very well put -- this is still true, in my opinion, regardless of “native” JSON support in Ruby 1.9 and higher. MultiJson is not a JSON serializer/deserializer, and provides a very good abstraction and common interface over JSON libraries, allowing users to pick the concrete implementations without changing the interface. Without an abstraction like this, library authors would have to provide this abstraction themselves. |
The author of multi_json is deprecating the library and recommends using the 'json' gem[1]. It also fixes issues where MultiJson calls #to_json and ActiveRecord::JSON implements IO#to_json to read on the file (which might fail if the IO is opened on read-only). [1]: intridea/multi_json#113
@karmi The benchmark was a very straightforward and simple, just load/dump a small object back and forth. The performance patch I've implemented made MultiJson significantly faster. It's still a bit slower than using the gems directly, but not by far. I continue maintaining the gem. |
Also I believe that multijson's overhead is constant isn't it ? With larger
|
MultiJson isn't all its cracked up to be. It can introduce slowness, its been removed as a dependency in activesupport, and there's now full, fast support for JSON in Ruby 1.9+. More info: intridea/multi_json#113 The fewer dependencies Crepe relies on, the better. If you need super-duper fast JSON in your app, use the YAJL gem and simply `require 'yajl/json_gem'` for full compatibility (though Ruby's JSON is now faster then the YAJL readme declares). Signed-off-by: Evan Owen <kainosnoema@gmail.com>
Fixes #1. For context, see #1 and intridea/multi_json#113 (comment).
I still prefer multi_json because stdlib "json" is slow and sometimes broken (with non-ASCII responses). Moreover multi_json is still supported and updated and supports different backends (like oj) |
I could be using the library incorrectly, but doing a very basic test, I see results that aren't really that great.
I've got a test and results in the following Gist:
https://gist.github.com/AaronRustad/d6f20229b9f19f6d163e
If I'm doing something incorrectly that is causing these numbers to appear worse than they should, please let me know.
Thanks!