[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Fleece: fast Lua to JSON
- From: Chris Babcock <cbabcock@...>
- Date: Sun, 20 Mar 2011 10:23:36 -0700
On Sun, Mar 20, 2011 at 2:52 AM, Alexander Gladysh <email@example.com> wrote:
>> I know that Python gets a lot of attention in discussions about
>> whether Lua is competitive in a web development environment...
>> I think that having a fast Lua to JSON translator takes
>> much away from one of the key attractions of ES5 in a web environment
>> - "Plays nice with Ajax."
> Note that Fleece is an one-way exporter.
> You do not need any sophisticated library to generate JSON from Lua
> code. (You need a parser to do this in reverse, of course.)
Right. The asymmetric optimization is very appropriate for the
emerging programming domain of HTML5 web applications.
At start up the user is requesting the current state of an object,
which could be a document, a game or just about anything else. This
state information is going to be on the server in a Lua table, either
retrieved from storage or (more likely) constructed in a Lua program.
The Lua table, which can contain a great deal of data, then needs to
be converted to JSON for the web-based client. This is a load time
process, which is an important part of the way the user experiences
Now assume you have multiple users editing a document or playing a
game. There are multiple clients submitting their changes in the
object model to the server. Each change is small, but the application
is going to combine the changes, calculate the effects, then push the
net change in object state out to all users. For document editing, the
server does little secondary processing on the data from the client to
apply it to the model and updates to the views sent server to client
are likely to be substantially similar, so there is a linear
relationship between c2s and s2c traffic for apps that are similar to
Google docs. In situations where each user has a unique view of the
data, e.g. an MMO game with first person perspective, the amount of
s2c JSON translation is going to be proportional to the square of c2s
JSON parsed by the server since each player is receiving the results
of all interactions. A 10 fold improvement in JSON parsing could be
more significant for some applications than the same improvement in
JSON generation, but that would need more than just low-level data
access to accomplish. Optimizing JSON output is more easily
accomplished, and it provides a dramatic performance improvement for
the server side code of a growing class of applications that is
currently very difficult to do well.
Yippee-ki-yay, coffee maker.