Re: [webkit-dev] Initializing String and AtomicString with literals

2012-08-28 Thread Eric Seidel
The wiki might also note that:

String bar = ASCIILiteral("foo");

is not free. :)  There is still a malloc() of a StringImpl under there.

On Mon, Aug 27, 2012 at 12:26 PM, Benjamin Poulain  wrote:
> On Sun, Aug 26, 2012 at 10:15 AM, Ojan Vafai  wrote:
>>
>> So, is the rule something like "Use ASCIILiteral unless you can show
>> improvement on a benchmark by using ConstructFromLiteral." Could you add
>> some simple explanation like that to the wiki page? As someone who doesn't
>> understand the implementation details, what's on the page right now doesn't
>> give me a clear enough rule of when to use which.
>
>
> I think it is a good rule, I added your sentence to the Wiki page.
>
> Benjamin
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] Initializing String and AtomicString with literals

2012-08-27 Thread Benjamin Poulain
On Sun, Aug 26, 2012 at 10:15 AM, Ojan Vafai  wrote:
>
> So, is the rule something like "Use ASCIILiteral unless you can show
> improvement on a benchmark by using ConstructFromLiteral." Could you add
> some simple explanation like that to the wiki page? As someone who doesn't
> understand the implementation details, what's on the page right now doesn't
> give me a clear enough rule of when to use which.
>

I think it is a good rule, I added your sentence to the Wiki page.

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


Re: [webkit-dev] Initializing String and AtomicString with literals

2012-08-26 Thread Ojan Vafai
On Fri, Aug 24, 2012 at 11:19 PM, Benjamin Poulain wrote:

> On Fri, Aug 24, 2012 at 10:18 PM, Adam Barth  wrote:
>
>> [[[
>> The difference between the version is if the length of the string is
>> included or not. Having the size given in the constructor makes the
>> constructor faster. Having the size also makes the code bigger, which
>> is a problem when the code is executed infrequently.
>> ]]]
>>
>> That description isn't 100% clear to me, but my reading of it is that
>> the ConstructFromLiteral version has the length of the string embedded
>> at the call site and therefore makes the code faster by increases the
>> code size.
>>
>
> Initially I thought avoiding strlen() would always be a win.
>
> In practice, I have learned the hard way that code growth can hurt us a
> lot on ARM so I wanted to provide a no-compromise option and added
> ASCIILiteral.
>
> If you use ASCIILiteral, the code does not grow a single byte. You can
> safely use it in any place where the default constructor was used and it
> always make the code faster.
>
> If you are in a place where the performance matter, or if the string is
> long and will not be used anytime soon, ConstructFromLiteral will give
> you better performance.
>

So, is the rule something like "Use ASCIILiteral unless you can show
improvement on a benchmark by using ConstructFromLiteral." Could you add
some simple explanation like that to the wiki page? As someone who doesn't
understand the implementation details, what's on the page right now doesn't
give me a clear enough rule of when to use which.


> Benjamin
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] Initializing String and AtomicString with literals

2012-08-24 Thread Benjamin Poulain
On Fri, Aug 24, 2012 at 10:05 PM, Adam Barth  wrote:

> Thanks!  The wiki page is very helpful.  I wonder if we should
> organize a hack-a-thon to deploy this pattern throughout WebKit.  Is
> there a way the compiler could give us a list of all the code location
> we should update?
>

We may discover interesting patterns and do even more improvements (e.g.:
the new StringBuilder::appendLiteral() or String::startsWith()).
I think the important is to fix the strings that are frequently
instantiated now, and then fix what's remaining in a hack-a-thon.

Cheers,
Benjamin
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] Initializing String and AtomicString with literals

2012-08-24 Thread Benjamin Poulain
On Fri, Aug 24, 2012 at 10:18 PM, Adam Barth  wrote:

> [[[
> The difference between the version is if the length of the string is
> included or not. Having the size given in the constructor makes the
> constructor faster. Having the size also makes the code bigger, which
> is a problem when the code is executed infrequently.
> ]]]
>
> That description isn't 100% clear to me, but my reading of it is that
> the ConstructFromLiteral version has the length of the string embedded
> at the call site and therefore makes the code faster by increases the
> code size.
>

Initially I thought avoiding strlen() would always be a win.

In practice, I have learned the hard way that code growth can hurt us a lot
on ARM so I wanted to provide a no-compromise option and added ASCIILiteral.

If you use ASCIILiteral, the code does not grow a single byte. You can
safely use it in any place where the default constructor was used and it
always make the code faster.

If you are in a place where the performance matter, or if the string is
long and will not be used anytime soon, ConstructFromLiteral will give you
better performance.

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


Re: [webkit-dev] Initializing String and AtomicString with literals

2012-08-24 Thread Maciej Stachowiak

On Aug 24, 2012, at 10:18 PM, Adam Barth  wrote:

> The wiki page says:
> 
> [[[
> The difference between the version is if the length of the string is
> included or not. Having the size given in the constructor makes the
> constructor faster. Having the size also makes the code bigger, which
> is a problem when the code is executed infrequently.
> ]]]
> 
> That description isn't 100% clear to me, but my reading of it is that
> the ConstructFromLiteral version has the length of the string embedded
> at the call site and therefore makes the code faster by increases the
> code size.

I see. Maybe we can tweak the syntax to make it more clear that it's a 
size/speed tradeoff (wasn't obvious to me from the wiki or the source for the 
header).

Cheers,
Maciej

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


Re: [webkit-dev] Initializing String and AtomicString with literals

2012-08-24 Thread Adam Barth
The wiki page says:

[[[
The difference between the version is if the length of the string is
included or not. Having the size given in the constructor makes the
constructor faster. Having the size also makes the code bigger, which
is a problem when the code is executed infrequently.
]]]

That description isn't 100% clear to me, but my reading of it is that
the ConstructFromLiteral version has the length of the string embedded
at the call site and therefore makes the code faster by increases the
code size.

Adam


On Fri, Aug 24, 2012 at 10:13 PM, Maciej Stachowiak  wrote:
>
> What's the difference between the ASCIILiteral and ConstructFromLiteral
> versions?
>
>  - Maciej
>
> On Aug 24, 2012, at 8:00 PM, Benjamin Poulain  wrote:
>
> Dear webkit-dev,
>
>
> Some recent changes improved the way we can use string classes with
> literals.
>
> There are 3 new constructors for initializing a string from a literal:
> -String(ASCIILIteral):
> http://trac.webkit.org/browser/trunk/Source/WTF/wtf/text/WTFString.h#L139
> -String(const char[], ConstructFromLiteralTag)
> -AtomicString(const char[], ConstructFromLiteralTag)
>
> The differences with the regular char* constructor are:
> -no memory is allocated for the bytes of the string.
> -the characters are not copied to the heap
> -String(const char[], ConstructFromLiteralTag) does not even access the
> bytes of the string.
>
> Those constructors are faster and use less memory in some cases.
> I converted some of the generated code to use the new constructors. In the
> future, please consider using ASCIILiteral() whenever constructing a String,
> and ConstructFromLiteral for a AtomicString.
>
> cheers,
> Benjamin
>
> PS: I started a Wiki page about the efficient use of the string classes:
> http://trac.webkit.org/wiki/EfficientStrings
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev
>
>
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


Re: [webkit-dev] Initializing String and AtomicString with literals

2012-08-24 Thread Maciej Stachowiak

What's the difference between the ASCIILiteral and ConstructFromLiteral 
versions?

 - Maciej

On Aug 24, 2012, at 8:00 PM, Benjamin Poulain  wrote:

> Dear webkit-dev,
> 
> 
> Some recent changes improved the way we can use string classes with literals.
> 
> There are 3 new constructors for initializing a string from a literal:
> -String(ASCIILIteral): 
> http://trac.webkit.org/browser/trunk/Source/WTF/wtf/text/WTFString.h#L139
> -String(const char[], ConstructFromLiteralTag)
> -AtomicString(const char[], ConstructFromLiteralTag)
> 
> The differences with the regular char* constructor are:
> -no memory is allocated for the bytes of the string.
> -the characters are not copied to the heap
> -String(const char[], ConstructFromLiteralTag) does not even access the bytes 
> of the string.
> 
> Those constructors are faster and use less memory in some cases.
> I converted some of the generated code to use the new constructors. In the 
> future, please consider using ASCIILiteral() whenever constructing a String, 
> and ConstructFromLiteral for a AtomicString.
> 
> cheers,
> Benjamin
> 
> PS: I started a Wiki page about the efficient use of the string classes: 
> http://trac.webkit.org/wiki/EfficientStrings
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev

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


Re: [webkit-dev] Initializing String and AtomicString with literals

2012-08-24 Thread Adam Barth
Thanks!  The wiki page is very helpful.  I wonder if we should
organize a hack-a-thon to deploy this pattern throughout WebKit.  Is
there a way the compiler could give us a list of all the code location
we should update?

Adam


On Fri, Aug 24, 2012 at 8:00 PM, Benjamin Poulain  wrote:
> Dear webkit-dev,
>
>
> Some recent changes improved the way we can use string classes with
> literals.
>
> There are 3 new constructors for initializing a string from a literal:
> -String(ASCIILIteral):
> http://trac.webkit.org/browser/trunk/Source/WTF/wtf/text/WTFString.h#L139
> -String(const char[], ConstructFromLiteralTag)
> -AtomicString(const char[], ConstructFromLiteralTag)
>
> The differences with the regular char* constructor are:
> -no memory is allocated for the bytes of the string.
> -the characters are not copied to the heap
> -String(const char[], ConstructFromLiteralTag) does not even access the
> bytes of the string.
>
> Those constructors are faster and use less memory in some cases.
> I converted some of the generated code to use the new constructors. In the
> future, please consider using ASCIILiteral() whenever constructing a String,
> and ConstructFromLiteral for a AtomicString.
>
> cheers,
> Benjamin
>
> PS: I started a Wiki page about the efficient use of the string classes:
> http://trac.webkit.org/wiki/EfficientStrings
>
> ___
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> http://lists.webkit.org/mailman/listinfo/webkit-dev
>
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev


[webkit-dev] Initializing String and AtomicString with literals

2012-08-24 Thread Benjamin Poulain
Dear webkit-dev,


Some recent changes improved the way we can use string classes with
literals.

There are 3 new constructors for initializing a string from a literal:
-String(ASCIILIteral):
http://trac.webkit.org/browser/trunk/Source/WTF/wtf/text/WTFString.h#L139
-String(const char[], ConstructFromLiteralTag)
-AtomicString(const char[], ConstructFromLiteralTag)

The differences with the regular char* constructor are:
-no memory is allocated for the bytes of the string.
-the characters are not copied to the heap
-String(const char[], ConstructFromLiteralTag) does not even access the
bytes of the string.

Those constructors are faster and use less memory in some cases.
I converted some of the generated code to use the new constructors. In the
future, please consider using ASCIILiteral() whenever constructing a
String, and ConstructFromLiteral for a AtomicString.

cheers,
Benjamin

PS: I started a Wiki page about the efficient use of the string classes:
http://trac.webkit.org/wiki/EfficientStrings
___
webkit-dev mailing list
webkit-dev@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-dev