Make sorted serialization faster

Redbean Lua and JSON serialization now goes faster because we're now
inserting object entries into tree data structure rather than making
an array and sorting it at the end. For example, when serializing an
object with 10,000 entries this goes twice as fast. However it still
goes slower than saying EncodeJson(x, {sorted=false}).
This commit is contained in:
Justine Tunney 2022-07-22 04:19:01 -07:00
parent 9de3d8f1e6
commit 84caee23ba
12 changed files with 122 additions and 224 deletions

View file

@ -41,7 +41,6 @@
#include "libc/sock/sock.h"
#include "libc/sock/struct/pollfd.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/strlist.internal.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ioprio.h"
#include "libc/sysv/consts/map.h"

View file

@ -783,9 +783,9 @@ FUNCTIONS
- sorted: (bool=true) Lua uses hash tables so the order of
object keys is lost in a Lua table. So, by default, we use
`qsort(strcmp)` to impose a deterministic output order. If
you don't care about ordering then setting `sorted=false`
should yield a 1.6x performance boost in serialization.
`strcmp` to impose a deterministic output order. If you
don't care about ordering then setting `sorted=false`
should yield a performance boost in serialization.
This function will return an error if:
@ -840,9 +840,9 @@ FUNCTIONS
- sorted: (bool=true) Lua uses hash tables so the order of
object keys is lost in a Lua table. So, by default, we use
`qsort(strcmp)` to impose a deterministic output order. If
you don't care about ordering then setting `sorted=false`
should yield a 2x performance boost in serialization.
`strcmp` to impose a deterministic output order. If you
don't care about ordering then setting `sorted=false`
should yield a performance boost in serialization.
If a user data object has a `__repr` or `__tostring` meta
method, then that'll be used to encode the Lua code.