Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unicode optimization in Lua cjson library (#1785)
The Lua cjson library implements an optimization that pre-allocates a string buffer by estimating the maximum memory used if all characters in a string require to be represented as unicode escapes, which may take 6 bytes each. Therefore, if a string has `len` bytes, the pre-allocated buffer will have `len * 6` bytes. This optimization can easily cause OOM errors, because if someone uses a string with a few gigabytes of size, the pre-allocator will require 6 times the size of that string, and when running the Lua script in a small instance with low memory, it will make the valkey-server process to abort. I ran the following Lua script to check if there is a significant performance regression: ``` local s = string.rep("a", 1024 * 1024 * 1024) return #cjson.encode(s..s..s) ``` The execution duration, in seconds, for 3 runs before and after this commit is the following: Before: 46.309; 42.443; 42.242 After: 46.729; 42.969; 42.774 --------- Signed-off-by: Ricardo Dias <ricardo.dias@percona.com> Signed-off-by: Ricardo Dias <rjd15372@gmail.com> Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
- Loading branch information