Skip to content

Vectorize basic_string::rfind (the string needle overload) - #5057

Merged
Stephan T. Lavavej (StephanTLavavej) merged 6 commits into
microsoft:mainfrom
AlexGuteniev:strrstr
Nov 14, 2024
Merged

Vectorize basic_string::rfind (the string needle overload)#5057
Stephan T. Lavavej (StephanTLavavej) merged 6 commits into
microsoft:mainfrom
AlexGuteniev:strrstr

Conversation

@AlexGuteniev

Copy link
Copy Markdown
Contributor

Towards #5036.

Similar to #5048, the differences:

Benchmark main this
member_rfind<not_highly_aligned_string>/0 108 ns 23.2 ns
member_rfind<not_highly_aligned_string>/1 101 ns 22.6 ns
member_rfind<not_highly_aligned_string>/2 1298 ns 305 ns
member_rfind<not_highly_aligned_string>/3 1554 ns 347 ns
member_rfind<not_highly_aligned_string>/4 7914 ns 4870 ns
member_rfind<not_highly_aligned_string>/5 15104 ns 15482 ns
member_rfind<not_highly_aligned_wstring>/0 98.1 ns 39.7 ns
member_rfind<not_highly_aligned_wstring>/1 101 ns 38.9 ns
member_rfind<not_highly_aligned_wstring>/2 1288 ns 624 ns
member_rfind<not_highly_aligned_wstring>/3 1559 ns 722 ns
member_rfind<not_highly_aligned_wstring>/4 5645 ns 9777 ns
member_rfind<not_highly_aligned_wstring>/5 15808 ns 20634 ns

constexpr data_and_pattern patterns[] = {
/* 0. Small, closer to end */ {lorem_ipsum, "aliquet"sv},
/* 1. Large, closer to end */ {lorem_ipsum, "aliquet malesuada"sv},
/* 2. Small, closer to begin */ {lorem_ipsum, "pulvinar"sv},
/* 3. Large, closer to begin */ {lorem_ipsum, "dapibus elit interdum"sv},
/* 4. Small, evil */ {fill_pattern_view<3000, false>, fill_pattern_view<7, true>},
/* 5. Large, evil */ {fill_pattern_view<3000, false>, fill_pattern_view<20, true>},
};

Comment thread stl/inc/__msvc_string_view.hpp Outdated
@StephanTLavavej

Copy link
Copy Markdown
Member

Results on my 5950X:

Benchmark Before After Speedup Notes
member_rfind<not_highly_aligned_string>/0 84.4 ns 21.5 ns 3.93 0: Small, closer to end
member_rfind<not_highly_aligned_string>/1 78.9 ns 21.1 ns 3.74 1: Large, closer to end
member_rfind<not_highly_aligned_string>/2 1336 ns 196 ns 6.82 2: Small, closer to begin
member_rfind<not_highly_aligned_string>/3 1590 ns 253 ns 6.28 3: Large, closer to begin
member_rfind<not_highly_aligned_string>/4 10408 ns 6720 ns 1.55 4: Small, evil
member_rfind<not_highly_aligned_string>/5 12419 ns 20189 ns 0.62 5: Large, evil
member_rfind<not_highly_aligned_wstring>/0 108 ns 32.3 ns 3.34 0: Small, closer to end
member_rfind<not_highly_aligned_wstring>/1 104 ns 31.5 ns 3.30 1: Large, closer to end
member_rfind<not_highly_aligned_wstring>/2 1845 ns 441 ns 4.18 2: Small, closer to begin
member_rfind<not_highly_aligned_wstring>/3 2148 ns 506 ns 4.25 3: Large, closer to begin
member_rfind<not_highly_aligned_wstring>/4 5756 ns 13644 ns 0.42 4: Small, evil
member_rfind<not_highly_aligned_wstring>/5 15833 ns 24849 ns 0.64 5: Large, evil

These are great speedups with only the evil cases being pessimized, and they aren't absolutely horrible.

@StephanTLavavej

Copy link
Copy Markdown
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej
Stephan T. Lavavej (StephanTLavavej) merged commit 7657fb0 into microsoft:main Nov 14, 2024
@StephanTLavavej

Copy link
Copy Markdown
Member

😹 🚀 😻 function! member basic_string important another vectorizing for Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Must go faster

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants