Skip to content

Optimize {__proto__:null} object literal creation#1118

Merged
bnoordhuis merged 1 commit intoquickjs-ng:masterfrom
bnoordhuis:opt-null-proto
Jul 28, 2025
Merged

Optimize {__proto__:null} object literal creation#1118
bnoordhuis merged 1 commit intoquickjs-ng:masterfrom
bnoordhuis:opt-null-proto

Conversation

@bnoordhuis
Copy link
Copy Markdown
Contributor

Speeds up the common pattern of creating prototype-less objects by 40%:

              TEST          N TIME (ns)  REF (ns) SCORE (%)
       object_null      20000    124.50

              TEST          N TIME (ns)  REF (ns) SCORE (%)
       object_null      50000     74.30

It's so much faster the benchmarker decides to run it 50,000 times instead of merely 20,000 times. Win.

Speeds up the common pattern of creating prototype-less objects by 40%:

                  TEST          N TIME (ns)  REF (ns) SCORE (%)
           object_null      20000    124.50

                  TEST          N TIME (ns)  REF (ns) SCORE (%)
           object_null      50000     74.30

It's so much faster the benchmarker decides to run it 50,000 times
instead of merely 20,000 times. Win.
Comment thread quickjs.c
goto exception;
break;
case OP_SPECIAL_OBJECT_NULL_PROTO:
*sp++ = JS_NewObjectProtoClass(ctx, JS_NULL, JS_CLASS_OBJECT);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried caching the shape for prototype-less objects on the JSContext (like it's done for ctx->array_shape) and calling JS_NewObjectFromShape(ctx, js_dup_shape(ctx->null_proto_shape), JS_CLASS_OBJECT) but it has no measurable impact on the micro-benchmark.

@bnoordhuis
Copy link
Copy Markdown
Contributor Author

Ping @saghul

@bnoordhuis bnoordhuis merged commit 0a00011 into quickjs-ng:master Jul 28, 2025
244 of 245 checks passed
@bnoordhuis bnoordhuis deleted the opt-null-proto branch July 28, 2025 13:09
mochaaP added a commit to mcha-forks/quickjs that referenced this pull request Oct 11, 2025
fixup: 0a00011 ("Optimize {__proto__:null} object literal creation", quickjs-ng#1118)
mochaaP added a commit to mcha-forks/quickjs that referenced this pull request Oct 14, 2025
fixup: 0a00011 ("Optimize {__proto__:null} object literal creation", quickjs-ng#1118)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants