On Mon, Apr 9, 2018 at 10:30 PM, Eric Rahm <er...@mozilla.com> wrote: >> Upon superficial code reading, it seems to me that currently changing >> the capacity of an nsA[C]STring might uselessly use realloc to copy >> data that's not semantically live data from the string's point of view >> and wouldn't really need to be preserved. Have I actually discovered >> useless copying or am I misunderstanding? > > > In this case I think you're right. In the string code we use a doubling > strategy up to 8MiB so they'll always be in a new bucket/chunk. After 8MiB > we grow by 1.125 [2], but always round up to the nearest MiB. Our > HugeRealloc logic always makes a new allocation if the difference is greater > than or equal to 1MiB [3] so that's always going to get hit. I should note > that on OSX we use some sort of 'pages_copy' when the realloc is large > enough, this is probably more efficient than memcpy.
Thanks. Being able to avoid useless copying for most strings probably outweighs the loss of the pages_copy optimization for huge strings on Mac. -- Henri Sivonen hsivo...@hsivonen.fi https://hsivonen.fi/ _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform