Hmmm... interesting topic.
I'm playing with implements a key value in-memory store, using
values[key] = value;
when values initially is {}.
When removing a key, I'm using
delete values[key]
Maybe, I should do
values[key] = null
and count the deletions. When reaching some count, I could copy all the
surviving keys (that is, that with associated value != null) to a new
object.
(My store is a tree. That is, if the key is users:1:name, the top store has
key 'users' pointing to a second level store, that has key 1 that points to
a third store that have key 'name'. The numeric keys are stored in a "big
integer set" implementation. Only alphanumeric keys are stored in
associative arrays/objects. So, I expect few keys per node level).
Comments?
Angel "Java" Lopez
http://ajlopez.zoomblog.com
http://twitter.com/ajlopez
On Fri, Jun 1, 2012 at 4:29 AM, Sven Panne <[email protected]> wrote:
> We only track property additions, because these are by far the most common
> case. Deleting a property results in going to "slow mode", i.e. using a
> dictionary for the object's properties. So as a general rule of thumb,
> using 'delete' makes thing slower.
>
> What are you trying to achieve exactly? Perhaps there's a way without
> using 'delete'.
>
> Cheers,
> S.
>
>
> On Fri, Jun 1, 2012 at 8:34 AM, Zenwolf <[email protected]> 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
>
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
>
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users