[libcxx-commits] [PATCH] D68617: partially inline copy constructor basic_string(const basic_string&[, allocator])

Martijn Vels via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 16 06:22:10 PDT 2019


mvels updated this revision to Diff 225205.
mvels added a comment.



1. Updating D68617 <https://reviews.llvm.org/D68617>: partially inline copy constructor basic_string(const basic_string&[, allocator]) #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

This change optimizes the copy constructor using partial inlining.

- adds default_value_tag() to memory, to support default initialization
- inlines copy contructor: non SSO init delegated to instantiated __init_long() method

Note that this change does not consider existing value initialization ctors, most would likely benefit from default initialization.

Generated code is small, i.e, considerably smaller than other hot inlined functions such as move ctor

given:

  void StringCopyCtor(void* mem, const std::string& s) {
      std::string*p = new(mem) std::string{s};
  }

asm:

          cmp     byte ptr [rsi + 23], 0
          js      .LBB0_2
          mov     rax, qword ptr [rsi + 16]
          mov     qword ptr [rdi + 16], rax
          movups  xmm0, xmmword ptr [rsi]
          movups  xmmword ptr [rdi], xmm0
          ret
  .LBB0_2:
          jmp     std::basic_string::__init_long # TAILCALL

Benchmarks::
BM_StringCopy_Empty                                           5.18ns ± 7%             1.53ns ± 5%  -70.45%        (p=0.000 n=10+10)
BM_StringCopy_Small                                           5.18ns ± 7%             1.54ns ± 5%  -70.21%        (p=0.000 n=10+10)
BM_StringCopy_Large                                           19.0ns ± 1%             19.3ns ± 1%   +1.77%        (p=0.000 n=10+10)
BM_StringCopy_Huge                                             321ns ± 4%              310ns ± 1%     ~            (p=0.408 n=10+8)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68617

Files:
  libcxx/include/memory
  libcxx/include/string

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68617.225205.patch
Type: text/x-patch
Size: 4130 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20191016/633b1ab0/attachment-0001.bin>


More information about the libcxx-commits mailing list