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

Improve Character method performance #75

Merged
merged 1 commit into from
Nov 30, 2022

Conversation

lahma
Copy link
Collaborator

@lahma lahma commented Sep 24, 2022

  • add SkipLocalsInit attribute
  • use pre-calculated answers for chars, generate using a test case using old methods
  • use HexConverter borrowed from .NET sources which has superior check performance for common case

This does change the Character.HexValue to return 0xff instead of 0 like before. But as it's invalid value I would consider it a corner case and better handle the way .NET libraries do it?

Reasoning and more fine-grained results can be found here:

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22621
AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
.NET SDK=7.0.100-rc.1.22431.12
  [Host]   : .NET 6.0.9 (6.0.922.41905), X64 RyuJIT
  ShortRun : .NET 6.0.9 (6.0.922.41905), X64 RyuJIT

Job=ShortRun  IterationCount=3  LaunchCount=1  
WarmupCount=3  

Parlot.Benchmarks.ParlotBenchmarks

Diff Method Mean Error Gen 0 Gen 1 Gen 2 Allocated
Old CreateCompiledSmallParser 56,338.023 ns 1,968.3448 ns 2.0142 0.9766 - 34,640 B
New 55,003.465 ns (-2%) 1,201.7026 ns 2.0142 (0%) 0.9766 (0%) - 34,640 B (0%)
Old CreateCompiledExpressionParser 10,915.005 ns 1,398.7247 ns 0.3357 0.1678 0.0153 5,688 B
New 10,330.240 ns (-5%) 187.2058 ns 0.3357 (0%) 0.1678 (0%) 0.0153 (0%) 5,688 B (0%)
Old CursorMatchHello 30.261 ns 1.6033 ns 0.0076 - - 128 B
New 30.814 ns (+2%) 0.3755 ns 0.0076 (0%) - - 128 B (0%)
Old CursorMatchGoodbye 32.938 ns 5.4822 ns 0.0076 - - 128 B
New 30.666 ns (-7%) 7.1631 ns 0.0076 (0%) - - 128 B (0%)
Old CursorMatchNone 24.658 ns 1.9902 ns 0.0076 - - 128 B
New 25.442 ns (+3%) 0.3252 ns 0.0076 (0%) - - 128 B (0%)
Old Lookup 32.622 ns 1.2212 ns 0.0076 - - 128 B
New 30.357 ns (-7%) 0.6192 ns 0.0076 (0%) - - 128 B (0%)
Old SkipWhiteSpace_1 27.005 ns 0.7584 ns 0.0076 - - 128 B
New 22.965 ns (-15%) 1.5206 ns 0.0076 (0%) - - 128 B (0%)
Old SkipWhiteSpace_10 40.532 ns 1.4653 ns 0.0076 - - 128 B
New 29.865 ns (-26%) 12.5532 ns 0.0076 (0%) - - 128 B (0%)
Old DecodeStringWithoutEscapes 6.904 ns 0.1219 ns - - - 0 B
New 7.712 ns (+12%) 0.0565 ns - - - 0 B
Old DecodeStringWithEscapes 70.397 ns 0.6172 ns 0.0072 - - 120 B
New 68.612 ns (-3%) 2.9249 ns 0.0072 (0%) - - 120 B (0%)
Old ExpressionRawSmall 229.810 ns 18.4341 ns 0.0181 - - 304 B
New 217.793 ns (-5%) 36.7999 ns 0.0181 (0%) - - 304 B (0%)
Old ExpressionCompiledSmall 428.956 ns 21.7107 ns 0.0391 - - 656 B
New 386.041 ns (-10%) 14.2656 ns 0.0391 (0%) - - 656 B (0%)
Old ExpressionFluentSmall 583.263 ns 23.7512 ns 0.0391 - - 656 B
New 530.177 ns (-9%) 18.2044 ns 0.0391 (0%) - - 656 B (0%)
Old ExpressionRawBig 1,156.974 ns 14.1275 ns 0.0706 - - 1,200 B
New 1,129.001 ns (-2%) 48.1586 ns 0.0706 (0%) - - 1,200 B (0%)
Old ExpressionCompiledBig 2,376.195 ns 201.3357 ns 0.1717 - - 2,888 B
New 2,124.498 ns (-11%) 38.6111 ns 0.1717 (0%) - - 2,888 B (0%)
Old ExpressionFluentBig 3,237.802 ns 54.4850 ns 0.1717 - - 2,888 B
New 2,928.574 ns (-10%) 230.3049 ns 0.1717 (0%) - - 2,888 B (0%)
Old BigJson 92,982.792 ns 14,716.9926 ns 5.9814 1.7090 - 101,672 B
New 92,182.898 ns (-1%) 4,901.0568 ns 5.9814 (0%) 1.7090 (0%) - 101,672 B (0%)
Old BigJsonCompiled 73,206.250 ns 6,353.9512 ns 5.9814 1.9531 - 101,672 B
New 75,104.378 ns (+3%) 2,620.1724 ns 5.9814 (0%) 1.9531 (0%) - 101,672 B (0%)
Old DeepJson 64,070.520 ns 4,004.4522 ns 6.7139 1.5869 - 112,976 B
New 61,565.955 ns (-4%) 6,416.8976 ns 6.7139 (0%) 1.5869 (0%) - 112,976 B (0%)
Old DeepJsonCompiled 41,217.159 ns 2,123.3436 ns 6.7139 2.1362 - 112,976 B
New 41,193.115 ns (0%) 1,414.2750 ns 6.7139 (0%) 2.1362 (0%) - 112,976 B (0%)
Old LongJson 78,860.205 ns 4,896.0293 ns 8.0566 2.6855 - 135,512 B
New 78,844.609 ns (0%) 13,264.2833 ns 8.0566 (0%) 2.6855 (0%) - 135,512 B (0%)
Old LongJsonCompiled 65,387.073 ns 9,289.1072 ns 8.0566 2.6855 - 135,512 B
New 61,799.943 ns (-5%) 7,839.5657 ns 8.0566 (0%) 2.6855 (0%) - 135,512 B (0%)
Old WideJson 42,593.520 ns 1,019.5747 ns 2.4414 0.4272 - 41,584 B
New 42,646.167 ns (0%) 107.7185 ns 2.4414 (0%) 0.4272 (0%) - 41,584 B (0%)
Old WideJsonCompiled 35,827.002 ns 8,399.4675 ns 2.4414 0.4272 - 41,584 B
New 34,939.266 ns (-2%) 3,123.3980 ns 2.4414 (0%) 0.4272 (0%) - 41,584 B (0%)

* add SkipLocalsInit attribute
* use pre-calculated answers for chars, generate using a test case using old methods
* use HexConverter borrowed from .NET sources which has superior check performance for common case
@lahma lahma requested a review from sebastienros September 25, 2022 13:02
@lahma
Copy link
Collaborator Author

lahma commented Nov 30, 2022

@sebastienros you no longer want to go fast? 🤔

@sebastienros
Copy link
Owner

Didn't notice this one ;)

@sebastienros sebastienros merged commit 233cc69 into sebastienros:main Nov 30, 2022
@lahma lahma deleted the character-improvements branch November 30, 2022 17:37
@lahma
Copy link
Collaborator Author

lahma commented Nov 30, 2022

If this lands as a release and consumed by Fluid, might be interesting to update the Fluid benchmarks 😉

@sebastienros
Copy link
Owner

I just published Fluid knowing that Parlot is on its way, I'll do a separate one with just Parlot updated. I didn't want to delay it. Checking if I need to add a net7.0 target, then will run the benchmarks.

@lahma
Copy link
Collaborator Author

lahma commented Nov 30, 2022

Sound good, I'm not in a hurry, Parlot has been fast enough 🙂

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

Successfully merging this pull request may close these issues.

2 participants