[njs] Optimising JSON.parse() for large objects.

Dmitry Volyntsev xeioex at nginx.com
Fri Apr 29 00:51:37 UTC 2022


details:   https://hg.nginx.org/njs/rev/4d71bdf8663d
branches:  
changeset: 1846:4d71bdf8663d
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Apr 28 17:49:59 2022 -0700
description:
Optimising JSON.parse() for large objects.

diffstat:

 src/njs_json.c |  10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diffs (28 lines):

diff -r 280e866c2973 -r 4d71bdf8663d src/njs_json.c
--- a/src/njs_json.c	Thu Apr 28 17:23:02 2022 -0700
+++ b/src/njs_json.c	Thu Apr 28 17:49:59 2022 -0700
@@ -877,8 +877,14 @@ njs_json_push_parse_state(njs_vm_t *vm, 
 
 
 njs_inline njs_json_state_t *
-njs_json_pop_parse_state(njs_json_parse_t *parse)
+njs_json_pop_parse_state(njs_vm_t *vm, njs_json_parse_t *parse)
 {
+    njs_json_state_t  *state;
+
+    state = &parse->states[parse->depth - 1];
+    njs_array_destroy(vm, state->keys);
+    state->keys = NULL;
+
     if (parse->depth > 1) {
         parse->depth--;
         return &parse->states[parse->depth - 1];
@@ -956,7 +962,7 @@ njs_json_parse_iterator(njs_vm_t *vm, nj
             }
 
         } else {
-            state = njs_json_pop_parse_state(parse);
+            state = njs_json_pop_parse_state(vm, parse);
             if (state == NULL) {
                 vm->retval = parse->retval;
                 return NJS_OK;



More information about the nginx-devel mailing list