Thanks for the useful information, Sven!

In my case, I have many instances of the same kind of object. In order to 
cut down on garbage collection at runtime, I created a pool that contains 
all instances. When I'm done with an instance, instead of freeing the 
reference and letting it be GC'd, I put it back into the pool so that I can 
reuse it.

I thought it would be a good idea to set all default primitive values on 
the prototype so that only the properties that were actually set would be 
created as local properties: the rest would be defaults shared across all 
instances.

When I put something back into the pool, I wanted to delete all local 
properties to "clean" the instance for reuse. Based on what you are saying, 
it seems that for performance I should NOT delete the properties, but 
rather maintain a set of all default properties on each instance, and then 
null them out.

Followup question based on the above: in a constructor when I establish all 
of my local properties, is it better to set them to default null value or 
to a default value of the same type that I intend to use for it (such as 
empty string, integer, etc.): does the value assigned to a local property 
in the constructor effect the way optimization will occur for the property?

Thanks very much!


On Thursday, May 31, 2012 11:34:07 PM UTC-7, Zenwolf wrote:
>
> Greetings all,
>
> Does using the JavaScript "delete" keyword to delete a property from an 
> object effect how v8 will optimize the object? I've read that v8 creates 
> hidden "classes" to represent an object and all its various property 
> configurations. Does deleting a property just flip between two of these 
> hidden classes and is it less efficient than just nulling the local 
> property value?
>
> Secondly, how will v8 handle the case where I have a prototype object with 
> "name" property and also a local property "name" and I delete the local 
> property to expose the prototype value again?
>
> Example:
>
> function Foo() {
>     this.name = 'foo';
> }
>
> function Bar() {}
> Bar.prototype = new Foo();
> var bar = new Bar();
> bar.name = 'bar';
> // later in the program...
> delete bar.name; // exposes prototype name again (Foo's name).
>
> Will using delete in such a manner prevent v8 from fully optimizing the 
> code? Or should I not worry about this usage?
>
> Thank you very much for any insight!
>
>
On Thursday, May 31, 2012 11:34:07 PM UTC-7, Zenwolf wrote:
>
> Greetings all,
>
> Does using the JavaScript "delete" keyword to delete a property from an 
> object effect how v8 will optimize the object? I've read that v8 creates 
> hidden "classes" to represent an object and all its various property 
> configurations. Does deleting a property just flip between two of these 
> hidden classes and is it less efficient than just nulling the local 
> property value?
>
> Secondly, how will v8 handle the case where I have a prototype object with 
> "name" property and also a local property "name" and I delete the local 
> property to expose the prototype value again?
>
> Example:
>
> function Foo() {
>     this.name = 'foo';
> }
>
> function Bar() {}
> Bar.prototype = new Foo();
> var bar = new Bar();
> bar.name = 'bar';
> // later in the program...
> delete bar.name; // exposes prototype name again (Foo's name).
>
> Will using delete in such a manner prevent v8 from fully optimizing the 
> code? Or should I not worry about this usage?
>
> Thank you very much for any insight!
>
>

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to