Small Buffer Optimization for string and friends

Daniel Murphy yebblies at nospamgmail.com
Sat Apr 7 23:33:55 PDT 2012


"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
news:jlr9ak$28bv$1 at digitalmars.com...
> 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.
>

This sounds like it would be a great addition to phobos.

> 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.

- This has been a disaster for AAs
- Is it worth doing for 32 bit?
- Would generate false pointers
- Run-time check on every array access?
- Why should this be in the language/compiler instead of phobos?

April 1st was last week!! 




More information about the Digitalmars-d mailing list