Skip to content
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

Question: generating JSON for react components: whats the point in using the gem if Rails .to_json is used for dumping #244

Closed
feliperaul opened this issue Jun 10, 2018 · 2 comments

Comments

@feliperaul
Copy link

Based on #89, it seems that the pattern to generate JSON for consuming in a react component is this:

render json: WidgetSerializer.new(widget).serialized_hash

Or, after #89 was merged, we can just pass the serializer instance to render :json, because all Rails does is calling .as_jon, which was aliased to .serializable_hash on #89.

But my question is: isn't the performance gains of this gem actually due to the generation of the stringified JSON? Because it seems that using this pattern we're just using fast_jsonapi to generate a Ruby Hash, and then leaving to Rails .to_json to actually stringify it (which I assume uses ActiveSupport::json.encode, based on this article)

Or am I missing something here?

@feliperaul feliperaul changed the title Question: generating JSON for react components Question: generating JSON for react components: whats the point in using the gem if Rails .to_json is used for dumping Jun 10, 2018
@shishirmk
Copy link
Collaborator

JSON dumping is very fast <5ms for most normal payloads if you use OJ, Yajl etc. Generating the ruby hash is generally what takes a lot of time in AMS. We have optimized that by focusing on jsonapi.org schema and optimizing for homogeneous arrays.

@feliperaul
Copy link
Author

@shishirmk Thanks for the valuable insight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants