Small Buffer Optimization for string and friends
Steven Schveighoffer
schveiguy at yahoo.com
Mon Apr 9 07:49:04 PDT 2012
On Sun, 08 Apr 2012 01:56:38 -0400, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> wrote:
> Walter and I discussed today about using the small string optimization
> in string and other arrays of immutable small objects.
>
> On 64 bit machines, string occupies 16 bytes. We could use the first
> byte as discriminator, which means that all strings under 16 chars need
> no memory allocation at all.
>
> It turns out statistically a lot of strings are small. According to a
> variety of systems we use at Facebook, the small buffer optimization is
> king - it just works great in all cases. In D that means better speed,
> better locality, and less garbage.
>
> For this to happen, we need to start an effort of migrating built-in
> arrays into runtime, essentially making them templates that the compiler
> lowers to. So I have two questions:
>
> 1. What happened to the new hash project? We need to take that to
> completion.
>
> 2. Is anyone willing to start the effort of migrating built-in slices
> into templates?
No, this would suck.
A better solution - make an *actual* string type that does this, and fixes
all the shitty problems that we have from shoehorning arrays into UTF
strings. Then alias that type to string.
I'm so sick of phobos trying to pretend char[] is not an array, and this
would just be another mark against D.
-Steve
More information about the Digitalmars-d
mailing list