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 <da...@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 > >
_______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev