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

2.0.0 -> 3.1.1 performance degradation #33

Closed
bugproof opened this issue Jan 5, 2022 · 2 comments
Closed

2.0.0 -> 3.1.1 performance degradation #33

bugproof opened this issue Jan 5, 2022 · 2 comments

Comments

@bugproof
Copy link
Contributor

bugproof commented Jan 5, 2022

https://github.com/bugproof/TomlLibrariesBenchmark

@dezhidki
Copy link
Owner

dezhidki commented Jan 5, 2022

Hi!

Thanks for bringing this up; this is quite a significant slowdown. After some basic profiling, it seems that the change to support TOML 1.0.0 caused a regression in date parsing performance:

kuva

The issue is likely the try-catch snippet which essentially causes unnecessary operations:

Tommy/Tommy/Tommy.cs

Lines 2011 to 2018 in 91e8fff

try
{
dateTime = parser(s, format, CultureInfo.InvariantCulture, styles);
}
catch (Exception)
{
continue;
}

Changing it back to original TryParse implementation indeed fixes the flamegraph:

kuva

Of course, supporting full TOML 1.0.0 spec causes a slight performance degradation that I cannot fully fix.
I pushed the fixed code right now (ecac69d, no release yet) if you feel like giving it a test. Here's the library if you don't want to compile it from the source:

Tommy.zip

I don't know about your testing setup, but on mine:

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1415 (21H2)
AMD Ryzen 5 3600, 1 CPU, 12 logical and 6 physical cores
.NET SDK=6.0.100
  [Host]     : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT
  DefaultJob : .NET 6.0.0 (6.0.21.52210), X64 RyuJIT

The fixed code now runs in 20.54 us, which is reasonable given the results with 2.0.0.

@bugproof
Copy link
Contributor Author

bugproof commented Jan 6, 2022

Quite a big difference after replacing exceptions with TryParse. I will update the benchmark results when new version will be on NuGet.

@bugproof bugproof closed this as completed Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants