This is an archive of the discontinued LLVM Phabricator instance.

Optimize / partially inline basic_string assignment operator
AbandonedPublic

Authored by mvels on Jan 3 2020, 9:02 AM.

Details

Summary

This change adds an optimization where assigning a short string value to a short string instance is optimized into a direct memory copy.

'As is', this optimization provides a 2X to 3X+ speed up.

BM_StringAssignStr_Empty_Opaque 5.23ns ± 0% 2.27ns ± 0% -56.62% (p=0.008 n=5+5)
BM_StringAssignStr_Empty_Transparent 5.14ns ± 0% 2.27ns ± 0% -55.89% (p=0.008 n=5+5)
BM_StringAssignStr_Small_Opaque 7.69ns ± 0% 2.27ns ± 0% -70.56% (p=0.008 n=5+5)
BM_StringAssignStr_Small_Transparent 7.65ns ± 0% 2.26ns ± 0% -70.41% (p=0.008 n=5+5)
BM_StringAssignStr_Large_Opaque 24.4ns ± 0% 25.6ns ± 0% +5.11% (p=0.008 n=5+5)
BM_StringAssignStr_Large_Transparent 22.2ns ± 0% 22.9ns ± 0% +3.43% (p=0.008 n=5+5)
BM_StringAssignStr_Huge_Opaque 320ns ± 3% 320ns ± 4% ~ (p=0.841 n=5+5)
BM_StringAssignStr_Huge_Transparent 321ns ± 4% 321ns ± 4% ~ (p=1.000 n=5+5)

Subsequently changing the assignment operator to be inlined (not externally instantiated) provides a speed up of 3X to 5X.

BM_StringAssignStr_Empty_Opaque 5.25ns ± 1% 1.71ns ± 0% -67.33% (p=0.008 n=5+5)
BM_StringAssignStr_Empty_Transparent 5.13ns ± 0% 1.29ns ± 0% -74.89% (p=0.008 n=5+5)
BM_StringAssignStr_Small_Opaque 7.69ns ± 0% 1.71ns ± 0% -77.70% (p=0.008 n=5+5)
BM_StringAssignStr_Small_Transparent 7.64ns ± 0% 1.29ns ± 0% -83.10% (p=0.008 n=5+5)
BM_StringAssignStr_Large_Opaque 24.4ns ± 0% 25.3ns ± 0% +3.97% (p=0.008 n=5+5)
BM_StringAssignStr_Large_Transparent 22.2ns ± 0% 22.6ns ± 0% +2.13% (p=0.008 n=5+5)
BM_StringAssignStr_Huge_Opaque 325ns ± 5% 315ns ± 6% ~ (p=0.222 n=5+5)
BM_StringAssignStr_Huge_Transparent 325ns ± 5% 316ns ± 5% ~ (p=0.310 n=5+5)

Event Timeline

mvels created this revision.Jan 3 2020, 9:02 AM
mvels edited the summary of this revision. (Show Details)Jan 3 2020, 9:04 AM
mvels added a reviewer: EricWF.
mvels abandoned this revision.Jan 3 2020, 9:06 AM