Skip to content
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

Use performant Object.create replacement #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

parshap
Copy link
Contributor

@parshap parshap commented Apr 16, 2014

Object.create is much slower than using the new operator in some versions of V8 (confirmed in Chrome 33 using V8 3.23, see this jsperf). This changes calls to Object.create() to a semantically-equivalent createObject() helper function that creates objects using a constructor function and the new operator.

This change also adds a basic benchmark script that can be run in node using npm run bench or served to the browser using npm run bench-server.

My benchmarks before the change:

create: 794.785ms
overwrite: 791.635ms
set: 800.428ms

And after the change:

create: 19.083ms
overwrite: 17.687ms
set: 15.335ms

Run `npm run bench` to run the benchmark script using node.

Run `PORT=8080 npm run bench-server` to start an HTTP server on port
8080 that will serve the benchmark script to browsers.
`Object.create` is much slower than creating objects using the `new`
operator in some versions of V8 (confirmed in Chrome 33 using V8 3.23).
This commit changes calls to `Object.create()` to use a
semantically-equivalent `createObject` helper function that creates
objects using a constructor function and the `new` keyword.

See http://jsperf.com/object-create-vs-constructor-vs-object-literal/49.
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