[webkit-dev] Optimization of buffer allocation of Vector and StringBuilder

Xianzhu Wang (王显著) wangxianzhu at chromium.org
Tue Oct 11 03:32:03 PDT 2011


I found replacing malloc/memcpy with realloc() can reduce many actual
allocations and copies. I tested with DumpRenderTree (using chromium's
tcmalloc) accessing 20 popular websites. In StringBuilder using realloc()
instead of malloc/memcpy when applicable, 45.3% of realloc()s return the
same pointer, i.e. no copies happen.

The replacement requires to add a StringImpl::reallocate() method.

WTF::Vector() doesn't have this issue because it's using realloc().

On Tue, Oct 11, 2011 at 3:14 AM, Darin Adler <darin at apple.com> wrote:

> On Oct 10, 2011, at 4:46 AM, Xianzhu Wang (王显著) wrote:
>
> > malloc_good_size() can get the rounded-up size of a required size, but it
> seems not available on all platforms. It's easy to implementation it over
> tcmalloc. On platforms that malloc_good_size() is not available, it's
> possible to get the mapping with a program and then hardcode the rules in
> WebKit, but I'm afraid if the rules could match the actual running
> environment. Any ideas?
>
> I think the key is to actually predict and measure the benefits of the
> change, ideally with real use cases.
>
> At one point I experimented with using this for string buffers expecting it
> to make code use less memory and be faster but when I did it I could not
> measure the benefit I expected.
>
> I think we can start by just not doing the tuning at all on platforms
> without a malloc_good_size and then dig deeper if we have a specific example
> of a problematic platform.
>
>    -- Darin
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20111011/7bb5947b/attachment.html>


More information about the webkit-dev mailing list