Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do a blank Ember Object this have a retained size of ~500

I tried creating an Ember object using

c = Em.Object.create();

and checked the memory dump to see this

enter image description here

It suggests a shallow memory of 24 and retained memory of 524. My Question is, is this something to worry in terms of memory if I am keeping around 500 such Ember Objects in a Controller.

So let us say I have a controller with 500 Ember Objects in the array content, then the momory dump looks like this:

enter image description here

Here each item in array has 524 retained size, and the controller has a large retained size of 268088 as a result. Is this really a problem?

I doubt if all the Ember objects are referring to the same 524bytes of some common object referred by each one of them.

like image 781
sabithpocker Avatar asked Aug 13 '13 11:08

sabithpocker


1 Answers

Ok I finally took a good look at Ember source and figured it out. It is because they are using delete.

(Ember has fixed this now and there should be no such drastic memory use by the blank ember objects anymore.)

delete tells V8 that "I will be using this object like a hash map rather than real object" and therefore switches to an internal hash map structure to store one's properties in rather than "C struct" like construct that is a core feature in the foundation modern javascript performance is built on.

When you look at the grey properties, it means the space taken by the internal storage which is a hash table and therefore takes a lot of space.

I have created a jsfiddle:

http://jsfiddle.net/JSbMJ/

You should run a heap snapshot and look for the objects and see how hugely their sizes differ (472 vs 80):

enter image description here

enter image description here

It is absolutely not a problem though because you are only supposed to do CRUD with ember, not games, physics simulations or such.

Btw, I don't know if other engines have such a reaction on delete but I figure they would because such an operation doesn't make sense when you semantically have an object and is impossible in many languages.

like image 157
Esailija Avatar answered Oct 21 '22 21:10

Esailija