Uh oh!
There was an error while loading. Please reload this page.
Streamline bool.TryParse/Format - #64782
Conversation
ghost
commented
Feb 4, 2022
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ghost
commented
Feb 4, 2022
Tagging subscribers to this area: @dotnet/area-system-runtime Issue Detailsprivatechar[]_true=newchar[]{'T','r','u','e'};privatechar[]_false=newchar[]{'F','a','l','s','e'};privatechar[]_somethingElse=newchar[]{'O','t','h','e','r'};[Benchmark]publicboolParseTrue()=>bool.TryParse(_true,out_);[Benchmark]publicboolParseFalse()=>bool.TryParse(_false,out_);[Benchmark]publicboolParseSomethingElse()=>bool.TryParse(_somethingElse,out_);[Benchmark]publicboolFormatTrue()=>true.TryFormat(_true,out_);[Benchmark]publicboolFormatFalse()=>false.TryFormat(_false,out_);
|
45ffc11 to
c7a32eaComparedanmoseley
commented
Feb 6, 2022
Do you think that TrimWhiteSpaceAndNull can be improved also? It's on the "not a boolean" path. |
c7a32ea to
1fd41cfComparestephentoub
commented
Feb 7, 2022
I don't see anything about the implementation that can be meaningfully improved without restoring to unsafe code, at least not until the JIT recognizes some sort of backward iteration pattern for bounds-check elimination. We can, however, push that whole trimming path off into a separate function, making it a bit cheaper to invoke the main parsing routine, along with being able to add a few more checks to more quickly weed out bad inputs.
|
danmoseley
commented
Feb 7, 2022
Assuming that once we get to trimming the result will usually be a failure, I wonder whether IndexOfAny(char[] { 'e', 'E' } might allow bailing out quickly if the input is large. |
stephentoub
commented
Feb 7, 2022
Have you seen any real-world cases of large inputs filled with whitespace and nulls being passed to bool.{Try}Parse? |
uweigand
commented
Feb 9, 2022
This commit introduced serious regressions on s390x, about 40 library test cases now fail. The problem seems to be that this (and similar lines): is incorrect on big-endian systems. The destination memory will be set up as the following bytes: while on a big-endian system, the string should actually be: I'm currently testing a fix. |
uweigand
commented
Feb 9, 2022
This is now #65078 |
EgorBo
commented
Feb 15, 2022
Improvements: dotnet/perf-autofiling-issues#3529 |
stephentoub
commented
Feb 15, 2022
Always nice when what you saw locally is mirrored by the lab subsequently :) |
Uh oh!
There was an error while loading. Please reload this page.