Page MenuHomePhabricator

Add a compiler option to make string resize/__resize_default_init use precise growth instead of amortized growth.
Needs ReviewPublic

Authored by ezbr on May 18 2021, 2:37 PM.

Details

Reviewers
EricWF
Group Reviewers
Restricted Project
Summary

In Google, we'd like to be able to test using precise growth rather than amortized growth in string resize methods in order to save memory. We intend to test internally and, assuming the effects are favorable, hopefully enable this behavior by default if possible in the future.

We expect that for use cases that don't require amortized exponential growth (i.e. are not repeatedly growing the same string), we can save up to 25% of the allocated memory without significantly increasing CPU usage. Cases in which resize is being used to repeatedly grow a particular string would be expected to regress in CPU usage, but these cases can be fixed by using reserve, either with a known maximum size or to do amortized exponential grow if the maximum size is unknown.

Diff Detail

Unit TestsFailed

TimeTest
2,550 mslibcxx CI ASAN > libc++.std/experimental/language_support/support_coroutines/end_to_end::expected.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/clang++ /home/libcxx-builder/.buildkite-agent/builds/45255b65aff5-1/llvm-project/libcxx-ci/libcxx/test/std/experimental/language.support/support.coroutines/end.to.end/expected.pass.cpp -v --target=x86_64-unknown-linux-gnu -g -fno-omit-frame-pointer -fsanitize=address -include /home/libcxx-builder/.buildkite-agent/builds/45255b65aff5-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/45255b65aff5-1/llvm-project/libcxx-ci/build/generic-asan/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/45255b65aff5-1/llvm-project/libcxx-ci/build/generic-asan/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/45255b65aff5-1/llvm-project/libcxx-ci/libcxx/test/support -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -O1 -std=c++2b -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -fmodules-cache-path=/home/libcxx-builder/.buildkite-agent/builds/45255b65aff5-1/llvm-project/libcxx-ci/build/generic-asan/projects/libcxx/test/std/experimental/language.support/support.coroutines/end.to.end/Output/expected.pass.cpp.dir/t.tmp/ModuleCache -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -fcoroutines-ts -lc++experimental -L/home/libcxx-builder/.buildkite-agent/builds/45255b65aff5-1/llvm-project/libcxx-ci/build/generic-asan/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/45255b65aff5-1/llvm-project/libcxx-ci/build/generic-asan/./lib -L/home/libcxx-builder/.buildkite-agent/builds/45255b65aff5-1/llvm-project/libcxx-ci/build/generic-asan/.
2,890 mslibcxx CI C++2b > libc++.libcxx/debug/containers::db_sequence_container_iterators.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/clang++-tot /home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/libcxx/debug/containers/db_sequence_container_iterators.pass.cpp -v --target=x86_64-unknown-linux-gnu -include /home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/support -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -std=c++2b -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -fmodules-cache-path=/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/projects/libcxx/test/libcxx/debug/containers/Output/db_sequence_container_iterators.pass.cpp.dir/t.tmp/ModuleCache -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -D_LIBCPP_DEBUG=1 -lc++experimental -L/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -L/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c…
3,800 mslibcxx CI C++2b > libc++.libcxx/gdb::gdb_pretty_printer_test.sh.cpp
Script: -- : 'RUN: at line 14'; /usr/bin/clang++-tot -v --target=x86_64-unknown-linux-gnu /home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/libcxx/gdb/gdb_pretty_printer_test.sh.cpp -o /home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp.exe -include /home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/support -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -std=c++2b -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -fmodules-cache-path=/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/projects/libcxx/test/libcxx/gdb/Output/gdb_pretty_printer_test.sh.cpp.dir/t.tmp/ModuleCache -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -g -lc++experimental -L/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -L/home/libcxx-builder/.buildkite…
1,190 mslibcxx CI C++2b > libc++.std/containers/sequences/vector/vector_cons::deduct.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/clang++-tot /home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/std/containers/sequences/vector/vector.cons/deduct.pass.cpp -v --target=x86_64-unknown-linux-gnu -include /home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/support -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -std=c++2b -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -fmodules-cache-path=/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/projects/libcxx/test/std/containers/sequences/vector/vector.cons/Output/deduct.pass.cpp.dir/t.tmp/ModuleCache -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -lc++experimental -L/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -L/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx…
1,160 mslibcxx CI C++2b > libc++.std/containers/sequences/vector_bool::assign_copy.pass.cpp
Script: -- : 'COMPILED WITH'; /usr/bin/clang++-tot /home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/std/containers/sequences/vector.bool/assign_copy.pass.cpp -v --target=x86_64-unknown-linux-gnu -include /home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/support/nasty_macros.h -nostdinc++ -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/include/c++/v1 -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/projects/libcxx/include/c++build -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/libcxx/test/support -D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER -std=c++2b -Werror -Wall -Wextra -Wshadow -Wundef -Wno-unused-command-line-argument -Wno-attributes -Wno-pessimizing-move -Wno-c++11-extensions -Wno-user-defined-literals -Wno-noexcept-type -Wno-atomic-alignment -Wsign-compare -Wunused-variable -Wunused-parameter -Wunreachable-code -Wno-unused-local-typedef -D_LIBCPP_DISABLE_AVAILABILITY -fcoroutines-ts -Werror=thread-safety -Wuser-defined-warnings -fmodules-cache-path=/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/projects/libcxx/test/std/containers/sequences/vector.bool/Output/assign_copy.pass.cpp.dir/t.tmp/ModuleCache -Wno-macro-redefined -D_LIBCPP_HAS_THREAD_API_PTHREAD -Wno-macro-redefined -D_LIBCPP_ABI_VERSION=1 -lc++experimental -L/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -L/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx-ci/build/generic-cxx2b/./lib -Wl,-rpath,/home/libcxx-builder/.buildkite-agent/builds/4fc23fbf4d4c-1/llvm-project/libcxx…
View Full Test Results (34 Failed)

Event Timeline

ezbr requested review of this revision.May 18 2021, 2:37 PM
ezbr created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2021, 2:37 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript

We're going to want some documentation about this option. Please add it here: https://libcxx.llvm.org/UsingLibcxx.html#id7
(The files that generate this are under libcxx/docs).

Generally options are discouraged, but this seems small enough. Can we describe in more depth what benefits this change hopes to provide?

ezbr updated this revision to Diff 352550.Wed, Jun 16, 2:01 PM

Updated configuration macro documentation.

ezbr edited the summary of this revision. (Show Details)Wed, Jun 16, 2:07 PM

I updated the documentation and added more details about the motivation to the revision summary.