Fleece: faster Lua to JSON - asking for a test drive

112 views
Skip to first unread message

Henning Diedrich

unread,
Mar 3, 2011, 6:54:22 PM3/3/11
to lua table semantics
Hi folks,

today I posted Fleece Lite to github. It is a C library specifically
to create a JSON string from Lua data, as fast as possible.

I achieved ten times faster conversion times then the other libraries
I found. (You find bench mark code in the test/ dir). See below on
how.

In keeping with the avant-garde aspirations of this list, before I
introduce Fleece to the Lua community at large, I would very much
appreciate if one or more of you took the time to download and test
it. Basically simply:

git clone git://github.com/Eonblast/fleece-lite.git fleece
cd fleece
make linux # (or macosx or macosx-old or ... can you contribute
windows? thanks!)
make test
make bench
make bench2

Should you like what you see, please continue:

make linux-test # (or macosx-test or macosx-old-test or ... can you
contribute windows? thanks!)
make bench3
lua test/test-fleece-rand.lua
make bench5 # (likely exhausts memory at some point)

And please let me know what performance you are seeing and of course,
any bugs or flaws you are finding. It's far from perfect, much is
missing. But the proof of concept is made I think. I'll be happy to
send anyone of you the full repo, should you care to inspect it. The
one at github is a cleaned up 'lite' version without history.

From the README ( http://eonblast.github.com/fleece-lite ):

* Sample

t = {1,2,3}
json_str = fleece.json(t)

* Functions

fleece.json() - convert (stringify) a Lua value to a JSON string
fleece.size() - dry run to find the JSON result size, without creating
it

* Compatibility

Fleece works with Lua 5.1.4 and 5.1.4-2, it can be adapted to other
Lua versions or LuaJIT and will be ported to 5.2.

* Performance

Part of its speed advantage over other JSON packages is derived from
the fact that it accesses the Lua table data at the core C level,
below the Lua C API, which frees a significant number of cycles. It
also uses a string buffer that is custom designed for the specific
task of building a JSON string. It uses custom programmed, faster
float and integer conversion and at the expense of some memory
consumtion, it keeps some string and lookup buffers around once
initialized, for the next encoding. Performance can be tuned by
tweaking buffer sizes at compile time, by setting defines in src/
fleece-intern.h. The defaults are set for Fleece to produce standard
JSON reasonably fast.

Have fun,
Henning
Reply all
Reply to author
Forward
0 new messages