-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Benchmark for strategy creation #1426
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...tNet.Artifacts/results/Polly.Core.Benchmarks.CreationBenchmark-report-github.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
``` | ||
|
||
BenchmarkDotNet v0.13.6, Windows 11 (10.0.22621.1992/22H2/2022Update/SunValley2) (Hyper-V) | ||
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores | ||
.NET SDK 7.0.306 | ||
[Host] : .NET 7.0.9 (7.0.923.32018), X64 RyuJIT AVX2 | ||
|
||
Job=MediumRun Toolchain=InProcessEmitToolchain IterationCount=15 | ||
LaunchCount=2 WarmupCount=10 | ||
|
||
``` | ||
| Method | Mean | Error | StdDev | Gen0 | Allocated | | ||
|------------ |-----------:|---------:|---------:|-------:|----------:| | ||
| Fallback_V7 | 114.8 ns | 1.84 ns | 2.70 ns | 0.0191 | 480 B | | ||
| Fallback_V8 | 4,324.7 ns | 21.92 ns | 31.43 ns | 0.2518 | 6504 B | | ||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow that's a lot more 😅 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think validation eats a lot of that as it involves reflection. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace Polly.Core.Benchmarks; | ||
|
||
#pragma warning disable CA1052 // Static holder types should be Static or NotInheritable | ||
|
||
public class CreationBenchmark | ||
{ | ||
[Benchmark] | ||
public static void Fallback_V7() | ||
{ | ||
Policy | ||
.HandleResult<string>(s => true) | ||
.FallbackAsync(_ => Task.FromResult("fallback")); | ||
} | ||
|
||
[Benchmark] | ||
public static void Fallback_V8() | ||
{ | ||
new ResilienceStrategyBuilder<string>() | ||
.AddFallback(new() | ||
{ | ||
FallbackAction = _ => Outcome.FromResultAsTask("fallback") | ||
}) | ||
.Build(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The creation in V8 is indeed more expensive as it involves a lot more infra. For this reason the recreation of strategies on hot path should be discouraged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would your generic recommendation be?
In the sandbox app the fallback behaviour is trivial and could be cached, but in the code on which it was based there's dynamic per-invocation behaviour going on to select the fallback.
It feels that to support the same behaviour the more performant option would be to drop Polly fallbacks entirely and deal with it at the call site like any "normal" code, which if true doesn't feel great that the performance for this scenario has actually gone backwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I have seen a scenario where you are "forced" to recreate a strategy on a hot path.
At worst you need to fallback to some dynamic value, but that can be archived by passing such value to the fallback action using
ResilienceContext
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In you code the caching could look like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you paste the code rather than a picture of it? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I tried to create a draft PR to your repo and got rejected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have the code forFallbackKeys
?Nevermind, I can see it in the screenshot.