Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Nov 14, 2024

Conversation

AlexGuteniev
Copy link
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>},
};

@AlexGuteniev AlexGuteniev requested a review from a team as a code owner October 31, 2024 06:16
@StephanTLavavej StephanTLavavej added the performance Must go faster label Oct 31, 2024
@StephanTLavavej StephanTLavavej self-assigned this Oct 31, 2024
@StephanTLavavej
Copy link
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 StephanTLavavej removed their assignment Nov 13, 2024
@StephanTLavavej StephanTLavavej self-assigned this Nov 14, 2024
@StephanTLavavej
Copy link
Member

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

@StephanTLavavej StephanTLavavej merged commit 7657fb0 into microsoft:main Nov 14, 2024
39 checks passed
@StephanTLavavej
Copy link
Member

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

@AlexGuteniev AlexGuteniev deleted the strrstr branch November 14, 2024 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants