Streamline bool.TryParse/Format#64782
Conversation
|
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. |
|
Tagging subscribers to this area: @dotnet/area-system-runtime Issue Details private char[] _true = new char[] { 'T', 'r', 'u', 'e' };
private char[] _false = new char[] { 'F', 'a', 'l', 's', 'e' };
private char[] _somethingElse = new char[] { 'O', 't', 'h', 'e', 'r' };
[Benchmark] public bool ParseTrue() => bool.TryParse(_true, out _);
[Benchmark] public bool ParseFalse() => bool.TryParse(_false, out _);
[Benchmark] public bool ParseSomethingElse() => bool.TryParse(_somethingElse, out _);
[Benchmark] public bool FormatTrue() => true.TryFormat(_true, out _);
[Benchmark] public bool FormatFalse() => false.TryFormat(_false, out _);
|
45ffc11 to
c7a32ea
Compare
|
Do you think that TrimWhiteSpaceAndNull can be improved also? It's on the "not a boolean" path. |
c7a32ea to
1fd41cf
Compare
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.
|
|
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. |
Have you seen any real-world cases of large inputs filled with whitespace and nulls being passed to bool.{Try}Parse? |
|
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. |
This is now #65078 |
|
Improvements: dotnet/perf-autofiling-issues#3529 |
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.