mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-08 20:28:30 +00:00
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:
parent
9de3d8f1e6
commit
84caee23ba
12 changed files with 122 additions and 224 deletions
|
@ -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"
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue