Use performant Object.create replacement#5
Open
parshap wants to merge 2 commits intoandrewdavey:masterfrom
Open
Use performant Object.create replacement#5parshap wants to merge 2 commits intoandrewdavey:masterfrom
parshap wants to merge 2 commits intoandrewdavey:masterfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Object.createis much slower than using thenewoperator in some versions of V8 (confirmed in Chrome 33 using V8 3.23, see this jsperf). This changes calls toObject.create()to a semantically-equivalentcreateObject()helper function that creates objects using a constructor function and thenewoperator.This change also adds a basic benchmark script that can be run in node using
npm run benchor served to the browser usingnpm run bench-server.My benchmarks before the change:
And after the change: