[all-commits] [llvm/llvm-project] 2bad22: Add optimization to basic_string::assign for compi...
Martijn Vels via All-commits
all-commits at lists.llvm.org
Mon Jun 29 11:34:59 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: 2bad2226801f32362036b471d35a40dc5f343632
https://github.com/llvm/llvm-project/commit/2bad2226801f32362036b471d35a40dc5f343632
Author: Martijn Vels <mvels at google.com>
Date: 2020-06-29 (Mon, 29 Jun 2020)
Changed paths:
M libcxx/include/__string
M libcxx/include/string
R libcxx/lib/abi/x86_64-apple-darwin.v2.abilist
Log Message:
-----------
Add optimization to basic_string::assign for compile-time known constant values.
Summary:
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)
```
Reviewers: EricWF, #libc!
Subscribers: jfb, libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D82221
More information about the All-commits
mailing list