The architecture of the Eonbeam game server called for an optimization in the Lua/JSON conversion.


The mailing list 'lua table semantics' has more information about the context of Fleece.

Fast Lua to JSON conversion

Fleece is a Lua extension library for fastest Lua to JSON conversion.

It beats other JSON packages by around 10 times. Fleece is produced for Eonblast's Eonbeam game servers to ruthlessly maximize throughput. Fleece Lite is Open Source.


Fleece Doc Page


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.


Tar: https://github.com/Eonblast/fleece-lite/tarball/master or

Git: git clone git://github.com/Eonblast/fleece-lite.git fleece


make linux # or linux-64, macosx, or make macosx-old


make test
make unit-tests


make bench
make bench2
make macosx-test # or linux-test, linux-64-test or macosx-old-test
make bench3


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

Sample Benchmark

lua test/bench3.lua
Fleece Benchmarks vs Json4 / native Lua and LuaJSON C lib
A couple of random tables are created and speed is clocked.
You should have built fleece first with 'make <PLATFORM>', 
and also built luajson.so with 'make <PLATFORM>-test,
and now be in the fleece root directory.
Lua 5.1 official - Fleece 0.2.4
1000 elements in t[i]=i                   
100x luajson.stringify(t)        3000ns/element           [1,2,3,4,5,6,7,8,9,1.. 
100x json4.encode(t)             7800ns/element           [1,2,3,4,5,6,7,8,9,1.. 
100x fleece.json(t)               300ns/element 10%,  3%  [1,2,3,4,5,6,7,8,9,1.. 
1000 elements in t['x'..i]=i              
100x luajson.stringify(t)        4700ns/element           {"x97":97,"x366":366.. 
100x json4.encode(t)            10600ns/element           {"x97":97,"x366":366.. 
100x fleece.json(t)               400ns/element  8%,  3%  {"x518":518,"x744":7.. 
1000 elements in t[i]=randstr(i)          
100x luajson.stringify(t)        2800ns/element           ["d","lnfbrryjnvabnr.. 
100x json4.encode(t)             9000ns/element           ["otkxtbnyemkrqdcyhh.. 
100x fleece.json(t)               200ns/element  7%,  2%  ["fgyqrqmmvkuouatzye.. 
1000 elements in t[randstr(i)]=randstr(i) 
100x luajson.stringify(t)        5300ns/element           {"bbwd":"kkpgojbhnor.. 
100x json4.encode(t)            12600ns/element           {"wvubdmsybdgtycqjg".. 
100x fleece.json(t)               500ns/element  9%,  3%  {"hfaxoxd":"yyndsgxy.. 
Note that fleece may list associative arrays in different order.