It is not as simple as one might think.
It requires streaming support by the JSON library itself since the point
is to start streaming the output *before* the JSON encoding is finished.
You should be able to pass the output streaming buffer object to the
JSON formatter library. For instance, suppose you have something like
this object:
{keyA: 'a value', keyB: anotherObject}
As the JSON formatter library reads this object, it would start with
some key, right? Suppose it starts with "keyA". So the browser would get
a chunk like this:
{"keyA": "a value"
Then it would get another chunk like:
, "keyB":
And it goes on until all object processing is finished. Of course I just
simplified the idea. What would really give a boost in my case would be
the ability to use multiple cores to format the JSON by splitting the
task in multiple threads (or processes depending on what Ruby
implementation the library is targetting to).
Since JSON became the de facto format to exchange data between servers
and browsers any effort to speed up its encoding/decoding (specially
encoding) would be of much value to any web framework.
I'd love to see some performance improvements over JSON responses.
Unfortunately I don't have time this year to work on such improvements
since I'm currently with a very tight deadline that has been already
missed due to Sandy's hurricane that affected our collocation service
provider in NYC.
Please let me know if I wasn't clear enough of what performance
improvements I'm suggesting to Rails 4 with regards to JSON responses.
Best,
Rodrigo.
Em 01-11-2012 12:23, Piotr Sarnacki escreveu:
As far as I know there is no plans to make it the default, but nothing
stops you from using ActionController::Live to stream JSON as soon as
you generate it.
On Thu, Nov 1, 2012 at 3:14 PM, Rodrigo Rosenfeld Rosas
<[email protected] <mailto:[email protected]>> wrote:
I have some pretty big data to be encoded to JSON in my
application and it would be faster if rendering my data as JSON
could be done with a stream response.
So, if the network is the bottleneck, the clients wouldn't notice
some seconds of delay before starting to receive the JSON response
that is required for the server to process JSON encoding before
starting to send it to the client...
Are you considering any kind of optimization like this for Rails 4?
--
You received this message because you are subscribed to the Google Groups "Ruby on
Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.