[libcxx-commits] [PATCH] D82220: Add optimization to basic_string::assign for compile-time known constant values.

Martijn Vels via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jun 19 11:27:00 PDT 2020


mvels created this revision.
mvels added reviewers: EricWF, ldionne.
Herald added a project: libc++.
Herald added a reviewer: libc++.
mvels retitled this revision from "This change optimizes the assign() methods for string where either the contents or lengths are compile time known constants. For small strings (< min_cap) we can execute the assignment entirely inline. For strings up to 128 bytes we allow the..." to "Add optimization to basic_string::assign for compile-time known constant values.".
mvels edited the summary of this revision.
mvels abandoned this revision.

This change optimizes the assign() methods for string where either the contents or lengths are compile time known constants. For small strings (< min_cap) we can execute the assignment entirely inline. For strings up to 128 bytes we allow the compiler to efficiently inline the copy operation after we call the offline __resize<>() method. Short / long branches are taken at the call site for better branch prediction and allowing FDO optimizations.

Benchmarks (unstable / google perflab):

  name                                                old time/op             new time/op             delta
  BM_StringAssignAsciiz_Empty_Opaque                  5.69ns ± 7%             5.97ns ± 7%     ~             (p=0.056 n=5+5)
  BM_StringAssignAsciiz_Empty_Transparent             5.39ns ± 7%             0.79ns ± 8%  -85.36%          (p=0.008 n=5+5)
  BM_StringAssignAsciiz_Small_Opaque                  11.2ns ± 5%             11.0ns ± 6%     ~             (p=0.548 n=5+5)
  BM_StringAssignAsciiz_Small_Transparent             10.1ns ± 7%              1.0ns ± 8%  -89.76%          (p=0.008 n=5+5)
  BM_StringAssignAsciiz_Large_Opaque                  23.5ns ± 7%             23.8ns ± 7%     ~             (p=0.841 n=5+5)
  BM_StringAssignAsciiz_Large_Transparent             21.4ns ± 7%             12.7ns ± 7%  -40.83%          (p=0.008 n=5+5)
  BM_StringAssignAsciiz_Huge_Opaque                    336ns ± 4%              327ns ± 7%     ~             (p=0.421 n=5+5)
  BM_StringAssignAsciiz_Huge_Transparent               331ns ± 5%              324ns ± 7%     ~             (p=0.548 n=5+5)
  BM_StringAssignAsciizMix_Opaque                     13.6ns ±10%             13.7ns ± 9%     ~             (p=0.690 n=5+5)
  BM_StringAssignAsciizMix_Transparent                12.9ns ± 8%              3.6ns ± 8%  -71.82%          (p=0.008 n=5+5)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82220

Files:
  libcxx/include/__string
  libcxx/include/string
  libcxx/lib/abi/x86_64-apple-darwin.v2.abilist

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82220.272144.patch
Type: text/x-patch
Size: 233562 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200619/5589d920/attachment-0001.bin>


More information about the libcxx-commits mailing list