Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Myles C. Maxfield
+1 :-)

On Friday, May 31, 2013, Glenn Adams wrote:

>
> On Fri, May 31, 2013 at 6:14 PM, Rafael Brandao 
>  'rafael.l...@openbossa.org');>
> > wrote:
>
>> This thread contains really useful information, so I've created a new
>> topic on https://trac.webkit.org/wiki/EfficientStrings and pointed to
>> here.
>>
>
> One thing that always threw me was the term "Atomic" in the class name. I
> wonder if the term "InternedString" would make it usage more apparent.
>
>
>>
>> Best regards,
>> Rafael
>>
>>
>> On Fri, May 31, 2013 at 8:32 PM, Ryosuke Niwa 
>> 
>> > wrote:
>>
>>> We shouldn't use AtomicString if the string we're about to create
>>> doesn't get shared across multiple AtomicStrings.
>>>
>>> For example, if we had used AtomicString for the strings inside Text
>>> nodes, then we may end up filling up the atomic string table with all these
>>> really long strings that don't typically appear more than once.  It also
>>> slows down the hash map look up for all other atomic strings.
>>>
>>> On Fri, May 31, 2013 at 3:00 PM, Brendan Long 
>>> 
>>> > wrote:
>>>
  So should I just never use String and always use AtomicString?


 On 05/31/2013 03:14 PM, Daker Pinheiro wrote:

 It is faster to compare and hash AtomicString than regular Strings.


 On Fri, May 31, 2013 at 5:57 PM, Brendan Long 
 
 > wrote:

> I hope this isn't a stupid question, but I can't find any references to
> what the difference between AtomicString and String is. It looks like
> AtomicString is generally preferred, but I don't know why. Can someone
> fill me in on this? Is there any refences for the classes in WTF?
>
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org  'webkit-dev@lists.webkit.org');>
> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
>


  --
 Daker Fernandes Pinheiro
 http://codecereal.blogspot.com



 ___
 webkit-dev mailing list
 webkit-dev@lists.webkit.org >>> 'webkit-dev@lists.webkit.org');>
 https://lists.webkit.org/mailman/listinfo/webkit-dev


>>>
>>> ___
>>> webkit-dev mailing list
>>> webkit-dev@lists.webkit.org >> 'webkit-dev@lists.webkit.org');>
>>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>>
>>>
>>
>>
>> --
>> Rafael Brandao @ INdT
>>
>> ___
>> webkit-dev mailing list
>> webkit-dev@lists.webkit.org > 'webkit-dev@lists.webkit.org');>
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>
>>
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Ryosuke Niwa
Great!  Maybe we even want to add it to
http://www.webkit.org/coding/technical-articles.html after converting it to
a web page?

- R. Niwa


On Fri, May 31, 2013 at 5:14 PM, Rafael Brandao
wrote:

> This thread contains really useful information, so I've created a new
> topic on https://trac.webkit.org/wiki/EfficientStrings and pointed to
> here.
>
> Best regards,
> Rafael
>
>
> On Fri, May 31, 2013 at 8:32 PM, Ryosuke Niwa  wrote:
>
>> We shouldn't use AtomicString if the string we're about to create doesn't
>> get shared across multiple AtomicStrings.
>>
>> For example, if we had used AtomicString for the strings inside Text
>> nodes, then we may end up filling up the atomic string table with all these
>> really long strings that don't typically appear more than once.  It also
>> slows down the hash map look up for all other atomic strings.
>>
>> On Fri, May 31, 2013 at 3:00 PM, Brendan Long wrote:
>>
>>>  So should I just never use String and always use AtomicString?
>>>
>>>
>>> On 05/31/2013 03:14 PM, Daker Pinheiro wrote:
>>>
>>> It is faster to compare and hash AtomicString than regular Strings.
>>>
>>>
>>> On Fri, May 31, 2013 at 5:57 PM, Brendan Long wrote:
>>>
 I hope this isn't a stupid question, but I can't find any references to
 what the difference between AtomicString and String is. It looks like
 AtomicString is generally preferred, but I don't know why. Can someone
 fill me in on this? Is there any refences for the classes in WTF?


 ___
 webkit-dev mailing list
 webkit-dev@lists.webkit.org
 https://lists.webkit.org/mailman/listinfo/webkit-dev


>>>
>>>
>>>  --
>>> Daker Fernandes Pinheiro
>>> http://codecereal.blogspot.com
>>>
>>>
>>>
>>> ___
>>> webkit-dev mailing list
>>> webkit-dev@lists.webkit.org
>>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>>
>>>
>>
>> ___
>> webkit-dev mailing list
>> webkit-dev@lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>
>>
>
>
> --
> Rafael Brandao @ INdT
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Glenn Adams
On Fri, May 31, 2013 at 6:14 PM, Rafael Brandao
wrote:

> This thread contains really useful information, so I've created a new
> topic on https://trac.webkit.org/wiki/EfficientStrings and pointed to
> here.
>

One thing that always threw me was the term "Atomic" in the class name. I
wonder if the term "InternedString" would make it usage more apparent.


>
> Best regards,
> Rafael
>
>
> On Fri, May 31, 2013 at 8:32 PM, Ryosuke Niwa  wrote:
>
>> We shouldn't use AtomicString if the string we're about to create doesn't
>> get shared across multiple AtomicStrings.
>>
>> For example, if we had used AtomicString for the strings inside Text
>> nodes, then we may end up filling up the atomic string table with all these
>> really long strings that don't typically appear more than once.  It also
>> slows down the hash map look up for all other atomic strings.
>>
>> On Fri, May 31, 2013 at 3:00 PM, Brendan Long wrote:
>>
>>>  So should I just never use String and always use AtomicString?
>>>
>>>
>>> On 05/31/2013 03:14 PM, Daker Pinheiro wrote:
>>>
>>> It is faster to compare and hash AtomicString than regular Strings.
>>>
>>>
>>> On Fri, May 31, 2013 at 5:57 PM, Brendan Long wrote:
>>>
 I hope this isn't a stupid question, but I can't find any references to
 what the difference between AtomicString and String is. It looks like
 AtomicString is generally preferred, but I don't know why. Can someone
 fill me in on this? Is there any refences for the classes in WTF?


 ___
 webkit-dev mailing list
 webkit-dev@lists.webkit.org
 https://lists.webkit.org/mailman/listinfo/webkit-dev


>>>
>>>
>>>  --
>>> Daker Fernandes Pinheiro
>>> http://codecereal.blogspot.com
>>>
>>>
>>>
>>> ___
>>> webkit-dev mailing list
>>> webkit-dev@lists.webkit.org
>>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>>
>>>
>>
>> ___
>> webkit-dev mailing list
>> webkit-dev@lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>
>>
>
>
> --
> Rafael Brandao @ INdT
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Rafael Brandao
This thread contains really useful information, so I've created a new topic
on https://trac.webkit.org/wiki/EfficientStrings and pointed to here.

Best regards,
Rafael


On Fri, May 31, 2013 at 8:32 PM, Ryosuke Niwa  wrote:

> We shouldn't use AtomicString if the string we're about to create doesn't
> get shared across multiple AtomicStrings.
>
> For example, if we had used AtomicString for the strings inside Text
> nodes, then we may end up filling up the atomic string table with all these
> really long strings that don't typically appear more than once.  It also
> slows down the hash map look up for all other atomic strings.
>
> On Fri, May 31, 2013 at 3:00 PM, Brendan Long wrote:
>
>>  So should I just never use String and always use AtomicString?
>>
>>
>> On 05/31/2013 03:14 PM, Daker Pinheiro wrote:
>>
>> It is faster to compare and hash AtomicString than regular Strings.
>>
>>
>> On Fri, May 31, 2013 at 5:57 PM, Brendan Long wrote:
>>
>>> I hope this isn't a stupid question, but I can't find any references to
>>> what the difference between AtomicString and String is. It looks like
>>> AtomicString is generally preferred, but I don't know why. Can someone
>>> fill me in on this? Is there any refences for the classes in WTF?
>>>
>>>
>>> ___
>>> webkit-dev mailing list
>>> webkit-dev@lists.webkit.org
>>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>>
>>>
>>
>>
>>  --
>> Daker Fernandes Pinheiro
>> http://codecereal.blogspot.com
>>
>>
>>
>> ___
>> webkit-dev mailing list
>> webkit-dev@lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>
>>
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
>


-- 
Rafael Brandao @ INdT
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Ryosuke Niwa
We shouldn't use AtomicString if the string we're about to create doesn't
get shared across multiple AtomicStrings.

For example, if we had used AtomicString for the strings inside Text nodes,
then we may end up filling up the atomic string table with all these really
long strings that don't typically appear more than once.  It also slows
down the hash map look up for all other atomic strings.

On Fri, May 31, 2013 at 3:00 PM, Brendan Long  wrote:

>  So should I just never use String and always use AtomicString?
>
>
> On 05/31/2013 03:14 PM, Daker Pinheiro wrote:
>
> It is faster to compare and hash AtomicString than regular Strings.
>
>
> On Fri, May 31, 2013 at 5:57 PM, Brendan Long wrote:
>
>> I hope this isn't a stupid question, but I can't find any references to
>> what the difference between AtomicString and String is. It looks like
>> AtomicString is generally preferred, but I don't know why. Can someone
>> fill me in on this? Is there any refences for the classes in WTF?
>>
>>
>> ___
>> webkit-dev mailing list
>> webkit-dev@lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>
>>
>
>
>  --
> Daker Fernandes Pinheiro
> http://codecereal.blogspot.com
>
>
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Darin Adler
On May 31, 2013, at 3:27 PM, Adam Barth  wrote:

> I believe we store a bit on StringImpl that makes conversion from String and 
> StringImpl to AtomicString fast
> if the underlying StringImpl is already in the AtomicStringTable.

Good point. Converting back to an atomic string costs only a single bit test 
and branch now; it’s almost free. My mistake.

-- Darin
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Adam Barth
On Fri, May 31, 2013 at 3:18 PM, Darin Adler  wrote:
> On May 31, 2013, at 1:57 PM, Brendan Long  wrote:
>> I hope this isn't a stupid question, but I can't find any references to what 
>> the difference between AtomicString and String is.
>
> WTF::AtomicString is a class that has four differences from the normal 
> WTF::String class:
>
> 1) It’s more expensive to create a new atomic string than a non-atomic 
> string; doing so requires a lookup in a per-thread atomic string hash table.
>
> 2) It’s very inexpensive to compare one atomic string with another. The cost 
> is just a pointer comparison. The actual string length and data don’t need to 
> be compared, because on any one thread no AtomicString can be equal to any 
> other AtomicString.
>
> 3) If a particular string already exists in the atomic string table, 
> allocating another string that is equal to it does not cost any additional 
> memory. The atomic string is shared and the cost is looking it up in the 
> per-thread atomic string hash table and incrementing its reference count.
>
> 4) There are special considerations if you want to use an atomic string on a 
> thread other than the one it was created on since each thread has its own 
> atomic string hash table.
>
> Generally speaking, we use AtomicString to make string comparisons fast and 
> to save memory when many equal strings are likely to be allocated. For 
> example, we use AtomicString for HTML attribute names so we can compare them 
> quickly, and for both HTML attribute names and values since it’s common to 
> have many identical ones and we save memory.
>
> It’s not a good idea to spend the extra cost to construct an AtomicString if 
> neither the comparison nor the memory savings applies.
>
> It’s unnecessarily costly to convert an atomic string to a non-atomic string 
> and then back to an atomic string, since it requires an additional hash table 
> lookup. Thus if you’re starting with an atomic string it’s best to keep the 
> value in variables of type AtomicString and AtomicStringImpl* if possible.

I don't mean to intrude, but I believe we store a bit on StringImpl
that makes conversion from String and StringImpl to AtomicString fast
if the underlying StringImpl is already in the AtomicStringTable:

https://trac.webkit.org/browser/trunk/Source/WTF/wtf/text/AtomicString.h#L185

ALWAYS_INLINE static PassRefPtr add(StringImpl* r)
{
if (!r || r->isAtomic())
return r;
return addSlowCase(r);
}

Adam
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Darin Adler
On May 31, 2013, at 1:57 PM, Brendan Long  wrote:

> I hope this isn't a stupid question, but I can't find any references to what 
> the difference between AtomicString and String is.

WTF::AtomicString is a class that has four differences from the normal 
WTF::String class:

1) It’s more expensive to create a new atomic string than a non-atomic string; 
doing so requires a lookup in a per-thread atomic string hash table.

2) It’s very inexpensive to compare one atomic string with another. The cost is 
just a pointer comparison. The actual string length and data don’t need to be 
compared, because on any one thread no AtomicString can be equal to any other 
AtomicString.

3) If a particular string already exists in the atomic string table, allocating 
another string that is equal to it does not cost any additional memory. The 
atomic string is shared and the cost is looking it up in the per-thread atomic 
string hash table and incrementing its reference count.

4) There are special considerations if you want to use an atomic string on a 
thread other than the one it was created on since each thread has its own 
atomic string hash table.

Generally speaking, we use AtomicString to make string comparisons fast and to 
save memory when many equal strings are likely to be allocated. For example, we 
use AtomicString for HTML attribute names so we can compare them quickly, and 
for both HTML attribute names and values since it’s common to have many 
identical ones and we save memory.

It’s not a good idea to spend the extra cost to construct an AtomicString if 
neither the comparison nor the memory savings applies.

It’s unnecessarily costly to convert an atomic string to a non-atomic string 
and then back to an atomic string, since it requires an additional hash table 
lookup. Thus if you’re starting with an atomic string it’s best to keep the 
value in variables of type AtomicString and AtomicStringImpl* if possible.

-- Darin
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Brendan Long
So should I just never use String and always use AtomicString?

On 05/31/2013 03:14 PM, Daker Pinheiro wrote:
> It is faster to compare and hash AtomicString than regular Strings.
>
>
> On Fri, May 31, 2013 at 5:57 PM, Brendan Long  > wrote:
>
> I hope this isn't a stupid question, but I can't find any
> references to
> what the difference between AtomicString and String is. It looks like
> AtomicString is generally preferred, but I don't know why. Can someone
> fill me in on this? Is there any refences for the classes in WTF?
>
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org 
> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
>
>
> -- 
> Daker Fernandes Pinheiro
> http://codecereal.blogspot.com
>



signature.asc
Description: OpenPGP digital signature
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Yoav Weiss
Are there any advantages to String over AtomicString?


On Fri, May 31, 2013 at 11:14 PM, Daker Pinheiro <
daker.pinhe...@openbossa.org> wrote:

> It is faster to compare and hash AtomicString than regular Strings.
>
>
> On Fri, May 31, 2013 at 5:57 PM, Brendan Long wrote:
>
>> I hope this isn't a stupid question, but I can't find any references to
>> what the difference between AtomicString and String is. It looks like
>> AtomicString is generally preferred, but I don't know why. Can someone
>> fill me in on this? Is there any refences for the classes in WTF?
>>
>>
>> ___
>> webkit-dev mailing list
>> webkit-dev@lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
>>
>>
>
>
> --
> Daker Fernandes Pinheiro
> http://codecereal.blogspot.com
>
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Daker Pinheiro
It is faster to compare and hash AtomicString than regular Strings.


On Fri, May 31, 2013 at 5:57 PM, Brendan Long  wrote:

> I hope this isn't a stupid question, but I can't find any references to
> what the difference between AtomicString and String is. It looks like
> AtomicString is generally preferred, but I don't know why. Can someone
> fill me in on this? Is there any refences for the classes in WTF?
>
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
>


-- 
Daker Fernandes Pinheiro
http://codecereal.blogspot.com
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


[webkit-dev] When should I use AtomicString vs String?

2013-05-31 Thread Brendan Long
I hope this isn't a stupid question, but I can't find any references to
what the difference between AtomicString and String is. It looks like
AtomicString is generally preferred, but I don't know why. Can someone
fill me in on this? Is there any refences for the classes in WTF?



signature.asc
Description: OpenPGP digital signature
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev