Drop EmptyObject and use Object.create(null) again
See original GitHub issueIt 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
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (8 by maintainers)
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.@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.