-
-
Notifications
You must be signed in to change notification settings - Fork 484
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
perf: Optimize regular numbers parse logics #990
perf: Optimize regular numbers parse logics #990
Conversation
432f828
to
a926285
Compare
Microbenchmark results
Baseline
Optimized
Test Code [MemoryDiagnoser]
[ExceptionDiagnoser]
[ShortRunJob(RuntimeMoniker.Net80)]
[ShortRunJob(RuntimeMoniker.Net47)]
public class AttemptUnknownTypeDeserializationBenchmarks
{
private static readonly IDeserializer deserializer = new DeserializerBuilder().WithAttemptingUnquotedStringTypeDeserialization().Build();
private static readonly string TestData =
"""
byteMaxValue: 255
shortMaxValue: 32767
longMaxValue : 9223372036854775807
ulongMaxValue: 18446744073709551615
floatMaxValue: 3.4028235E+38
doubleMaxValue: 1.7976931348623157E+308
""";
[Benchmark]
public object? Deserialize()
{
return deserializer.Deserialize(TestData);
}
} |
YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs
Outdated
Show resolved
Hide resolved
YamlDotNet/Serialization/NodeDeserializers/ScalarNodeDeserializer.cs
Outdated
Show resolved
Hide resolved
I like performance fixes. And this is a pretty big one! If you can address the 2 comments then I'll merge this in and get it out. |
Apart from this PR. Above regex checking Is it able to change Regex to use more strict regex with |
You can add those to that regex without any issue I would think. |
Thanks for your response. |
I've removed wrong comment in commit.
|
This PR intended to optimize performance for number deserialization by changing Parse to
TryParse
method.It's discussed at #794
Additionally this PR fix
double
value deserialization problems that are found on UnitTests.What's Changes
Parse
logics withTryParse
method.float
/double
parse logics for.NET Framework
.double
, then checks float value ranges.UnquotedStringTypeDeserialization_RegularNumbers
).NET Behavior differences
On .NET Framework.
float.Parse((double.MaxValue + 1).ToString())
throwOverflowException
.But on .NET Core. It returns PosititiveInfinite(
∞
).These behavior differences are described at Single.Parse Method page.
On current implementation.
Values outside the range of the
float
type are converted to-∞
/∞
.So I've added logics to check float value ranges.