From: Dmitry Volyntsev Date: Thu, 3 Sep 2026 00:39:41 +0000 (-0700) Subject: Tests: add parser stress benchmarks X-Git-Tag: 1.0.2~71 X-Git-Url: https://git.kaiwu.me/%7B@url%7D?a=commitdiff_plain;h=e90bdd14691b7a1ad67b83b5513da62f4e36a061;p=njs.git Tests: add parser stress benchmarks Add generated workloads for large array literals, declarations, references, closures, and labels. These tests are intended to expose catastrophic parser scaling and compare compilation changes; source construction and Function() compilation are both included in the measured interval. --- diff --git a/src/test/njs_benchmark.c b/src/test/njs_benchmark.c index cdb5954e..896f3fcb 100644 --- a/src/test/njs_benchmark.c +++ b/src/test/njs_benchmark.c @@ -119,6 +119,11 @@ njs_benchmark_test(njs_vm_t *parent, njs_opts_t *opts, njs_value_t *report, options.backtrace = 1; options.addons = njs_benchmark_addon_external_modules; + if (strncmp(test->name, "compile ", njs_length("compile ")) == 0) { + options.max_stack_size = 64 * 1024 * 1024; + options.unsafe = 1; + } + vm = NULL; nvm = NULL; ret = NJS_ERROR; @@ -286,6 +291,45 @@ static njs_benchmark_test_t njs_test[] = njs_str("4"), 100000 }, + { "compile array references 1M", + njs_str("Function('var x; return [' + 'x,'.repeat(999999) + 'x]'); 1"), + njs_str("1"), + 1 }, + + { "compile sequential block declarations 100K", + njs_str("Function('{let x=0;}'.repeat(100000)); 1"), + njs_str("1"), + 1 }, + + { "compile sequential labels 100K", + njs_str("Function('a:;'.repeat(100000)); 1"), + njs_str("1"), + 1 }, + + { "compile unique declarations 100K", + njs_str("Function(Array(100000).fill(0)" + ".map((v, i) => 'let x' + i + '=0;').join('')); 1"), + njs_str("1"), + 1 }, + + { "compile referenced declarations 100K", + njs_str("Function(Array(100000).fill(0)" + ".map((v, i) => 'let x' + i + '=0;x' + i + ';').join('')); 1"), + njs_str("1"), + 1 }, + + { "compile closures 20K", + njs_str("Function('void function(){let x=1;return ()=>x;};'" + ".repeat(20000)); 1"), + njs_str("1"), + 1 }, + + { "compile nested labels 10K", + njs_str("Function(Array(10000).fill(0)" + ".map((v, i) => 'a' + i + ':').join('') + ';'); 1"), + njs_str("1"), + 1 }, + { "string create 'abcdefABCDEF'", njs_str("benchmark.string('create', 'abcdef', 1000000)"), njs_str("undefined"),