Skip to content

Optimize {__proto__:null} object literal creation #1118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.
@@ -16748,6 +16749,11 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj,
if (unlikely(JS_IsException(sp[-1])))
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.

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.

1 participant