Add json_object_array_shrink() (and array_list_shrink()) and use it in json_tokener to minimize the amount of memory used. This results in a 39%-50% reduction in memory use (peak RSS, peak heap usage) on the jc-bench benchmark and 9% shorter runtime.
Also add the json_object_new_array_ext, array_list_new2, and array_list_shrink functions.
This commit is contained in:
1 parent
99bb2121c6
commit
e26a1195f4
6 files changed
+95
-3
No files matched your search
@@ -964,6 +964,9 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
|
||||
case json_tokener_state_array:
|
||||
if (c == ']')
|
||||
{
|
||||
// Minimize memory usage; assume parsed objs are unlikely to be changed
|
||||
json_object_array_shrink(current, 0);
|
||||
|
||||
if (state == json_tokener_state_array_after_sep &&
|
||||
(tok->flags & JSON_TOKENER_STRICT))
|
||||
{
|
||||
@@ -997,6 +1000,9 @@ struct json_object *json_tokener_parse_ex(struct json_tokener *tok, const char *
|
||||
case json_tokener_state_array_sep:
|
||||
if (c == ']')
|
||||
{
|
||||
// Minimize memory usage; assume parsed objs are unlikely to be changed
|
||||
json_object_array_shrink(current, 0);
|
||||
|
||||
saved_state = json_tokener_state_finish;
|
||||
state = json_tokener_state_eatws;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user