[libcxx-commits] [PATCH] D102727: Add a compiler option to make string resize/__resize_default_init use precise growth instead of amortized growth.

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jul 5 09:05:30 PDT 2021


ldionne requested changes to this revision.
ldionne added a comment.
This revision now requires changes to proceed.

If this is only an experiment and we're not sure we want to keep it, I would much prefer that you enable it internally in your downstream fork and then upstream it alongside with the data you gathered if the experiment turns out to be positive. When we add options to libc++, people are free to start using them and they are a lot harder to remove. I'd be happy to make this the default in libc++ if it's shown to be an improvement and keeps us conforming.

Regarding the change itself, let me make sure I understand. Basically, this patch calls `reserve(n)` automatically whenever someone calls `resize(n)`, so that we end up not growing the string exponentially in `append()` if we don't have enough capacity. Another way to achieve this would be to *not* perform `2 * __old_cap` in `__grow_by_and_replace()`, however this would also mean that a loop using `push_back()` repeatedly would have quadratic complexity (because we'd be growing by exactly 1 element each time), which is bad. Is that right, and is that why you're only adding this knob in `resize()`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102727/new/

https://reviews.llvm.org/D102727



More information about the libcxx-commits mailing list