Skip to content

Conversation

bnoordhuis
Copy link
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.
goto exception;
break;
case OP_SPECIAL_OBJECT_NULL_PROTO:
*sp++ = JS_NewObjectProtoClass(ctx, JS_NULL, JS_CLASS_OBJECT);
Copy link
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
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)
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