Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Optimized string.Replace(char, char) #67049
Optimized string.Replace(char, char) #67049
Changes from 10 commits
549d7c4
7dfe855
5232726
a442549
4e99ac4
30889ac
8627f6f
ed83650
5d92816
0ee90f4
0a7ca74
c65192a
35679cb
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you quantify this? Even with good branch prediction it's still more expensive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to pour this statement into numbers, as with a BDN-benchmark the branch predictor will very likely do a great job (they got really smart over the last generation of cpus).
In contrast to real-world usage I assume that it is more likely to have$> 0$ elements remaining than having a remainder of $= 0$ . In that case, and with the assumption that the branch predictor predictis $> 0$ elements, the additional check (would be a
test
-instruction on x86) costs more than just executing the code (which needs to be done anyway).So we penalize the case of having 0 elements remaining (which is assumed to be less likely), but all the data should be in the cache and cpu's memory system's store buffer should help to minimize that penalty.
When I start working on Vector128/256 support for
string.Replace
I'll try to examine that further, as there may be a code-path that starts with Vector256 where remainders will be processed by Vector128.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps worth adding an assert that current
Debug.Assert(this.Length - i <= Vector<ushort>.Count)
to make sure we won't skip any data?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think in this case a test should fail?
I'll re-check the tests and make sure that case is covered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests cover these cases, so I don't see a need for the Debug.Assert -- but I'll add it of course if you want.
runtime/src/libraries/Common/tests/Tests/System/StringTests.cs
Lines 4566 to 4578 in 8ed8517