[libcxx-commits] [PATCH] D72179: Optimize basic_string::assign(s [, n]) for compile time known short strings.

Martijn Vels via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 3 13:30:25 PST 2020


mvels created this revision.
Herald added subscribers: libcxx-commits, christof.
Herald added a project: libc++.

This change dispatches assignments of strings which length is known at compile time and smaller than __min_cap to an inlined __assign_in_place() method. This allows the compiler to fully optimize the assignment, removing outline memcpy calls, resulting in up to 6X speed ups for small string assignments.

BM_StringAssignAsciiz_Empty_Transparent             7.30ns ± 0%             1.01ns ± 0%  -86.19%          (p=0.008 n=5+5)
BM_StringAssignAsciiz_Small_Opaque                  10.9ns ± 0%              9.9ns ± 0%   -9.06%          (p=0.008 n=5+5)
BM_StringAssignAsciiz_Small_Transparent             9.92ns ± 0%             1.33ns ± 0%  -86.61%          (p=0.008 n=5+5)
BM_StringAssignAsciiz_Large_Opaque                  33.7ns ± 0%             30.2ns ± 1%  -10.21%          (p=0.008 n=5+5)
BM_StringAssignAsciiz_Large_Transparent             30.8ns ± 0%             27.2ns ± 0%  -11.53%          (p=0.008 n=5+5)
BM_StringAssignAsciiz_Huge_Opaque                    388ns ± 4%              391ns ± 3%     ~             (p=1.000 n=5+5)
BM_StringAssignAsciiz_Huge_Transparent               385ns ± 4%              388ns ± 3%     ~             (p=1.000 n=5+5)
BM_StringAssignAsciizMix_Opaque                     15.9ns ± 0%             14.1ns ± 0%  -11.62%          (p=0.008 n=5+5)
BM_StringAssignAsciizMix_Transparent                15.4ns ± 0%              7.5ns ± 1%  -50.97%          (p=0.008 n=5+5)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72179

Files:
  libcxx/include/__config
  libcxx/include/string

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72179.236118.patch
Type: text/x-patch
Size: 7935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200103/ba49fbeb/attachment.bin>


More information about the libcxx-commits mailing list