[PATCH] D55045: Add a version of std::function that includes a few optimizations.
Jordan Soyke via Phabricator
reviews at reviews.llvm.org
Thu Nov 29 20:13:18 PST 2018
jsoyke added a comment.
Current benchmark output with clang-7: F7625674: benchmark_output.txt <https://reviews.llvm.org/F7625674>
And a paste of it for easy viewing: https://pastebin.com/raw/5P5zqtuy
One of the most important parts of this change in system-level benchmarks is eliminating the 3 levels of pointer / vtable indirection (__f_ -> vtable -> operator()) and 1 conditional in std::function::operator() (which doesn't really show up in the micro-benchmark, presumably because the cache stays hot or the compiler can optimize it very easily).
There are some alternative versions of this change that are worth considering, for example we could only eliminate the conditional in operator() and only eliminate one level of pointer indirection, which would allow for larger inline captures (up to sizeof(void*)*3, which happens to be large enough to accommodate most containers captured by value).
Another possibility is always storing non-trivial data out-of-line, which makes move operations really fast at the expense of an extra allocation for small non-trivial objects (in some of our codebases moving std::functions tends to be done in critical regions, like popping off of a thread-safe work queue, so the extra allocation may be worth it for some workloads).
CHANGES SINCE LAST ACTION
More information about the libcxx-commits