question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drop EmptyObject and use Object.create(null) again

See original GitHub issue

It seems that new EmptyObject was added as a work-around for Object.create(null) performance. This has a couple of drawbacks for Ember itself, but also comes with a performance penalty in recent Chrome versions (i.e. in all current channels) that include this CL.

From what I can tell, new EmptyObject is often used to create objects that are supposed to be used as dictionaries. But at least in V8 function constructors always create fast mode objects, which means Ember probably wastes (metadata) memory in the browser plus time just to let the engine figure out that it should essentially transition these objects to dictionary mode objects. Object.create(null) always creates a dictionary mode object from the start (since the aforementioned CL landed), and it’s compatible with jQuery.isPlainObject and other stuff. The allocation is roughly on par with the performance of new EmptyObject in all current Chrome channels.

So I’d like to trigger a discussion to get rid of EmptyObject.

/cc @krisselden @stefanpenner

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
verwaest-zzcommented, Mar 14, 2017

Note that as we speak we’re also adding support for {__proto__:null} which will probably be even faster (can be fully recognized in the parser). Object.create(null) will of course be available slightly sooner.

1reaction
bmeurercommented, Mar 27, 2017

@lpinca Yap, the allocation is only inlined into TurboFan, and as such escape analysis can only remove the allocation in TurboFan. But an Object.create(null) that doesn’t escape isn’t very useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Impacts and benefits of creating empty object using Object ...
I think creating objects with Object.create(null) generally unnecessary and not worth the browser compatibility and clarity you sacrifice.
Read more >
Object.create() - JavaScript - MDN Web Docs
The Object.create() method creates a new object, using an existing object as the prototype of the newly created object.
Read more >
Object.create() - JavaScript - UDN Web Docs: MDN Backup
create () method creates a new object, using an existing object as the prototype of the newly created object.
Read more >
Handling JSON null and empty arrays and objects - IBM
The JSON empty concept applies for arrays and objects as shown below. ... In the case of address, an empty address data object...
Read more >
Objects - The Modern JavaScript Tutorial
An empty object (“empty cabinet”) can be created using one of two syntaxes: ... To remove a property, we can use the delete...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found