-
-
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
Improve the V8 -> V7 bridge implementation and add benchmarks #1257
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
...DotNet.Artifacts/results/Polly.Core.Benchmarks.BridgeBenchmark-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 @@ | ||
``` ini | ||
|
||
BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.1702/22H2/2022Update/SunValley2), VM=Hyper-V | ||
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 16 logical and 8 physical cores | ||
.NET SDK=7.0.302 | ||
[Host] : .NET 7.0.5 (7.0.523.17405), X64 RyuJIT AVX2 | ||
|
||
Job=MediumRun Toolchain=InProcessEmitToolchain IterationCount=15 | ||
LaunchCount=2 WarmupCount=10 | ||
|
||
``` | ||
| Method | Mean | Error | StdDev | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | | ||
|----------------------- |----------:|---------:|---------:|------:|--------:|-------:|----------:|------------:| | ||
| NoOpAsync | 85.38 ns | 1.001 ns | 1.371 ns | 1.00 | 0.00 | 0.0120 | 304 B | 1.00 | | ||
| NullResilienceStrategy | 416.38 ns | 1.924 ns | 2.820 ns | 4.87 | 0.10 | 0.0148 | 376 B | 1.24 | | ||
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,22 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace Polly.Core.Benchmarks; | ||
|
||
public class BridgeBenchmark | ||
{ | ||
private IAsyncPolicy<string>? _policy; | ||
private IAsyncPolicy<string>? _policyWrapped; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_policy = Policy.NoOpAsync<string>(); | ||
_policyWrapped = NullResilienceStrategy<string>.Instance.AsAsyncPolicy(); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public Task NoOpAsync() => _policy!.ExecuteAsync(() => Task.FromResult("dummy")); | ||
|
||
[Benchmark] | ||
public Task NullResilienceStrategy() => _policyWrapped!.ExecuteAsync(() => Task.FromResult("dummy")); | ||
} |
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,20 @@ | ||
using System.Collections.Generic; | ||
using Polly.Utils; | ||
|
||
namespace Polly.Core.Tests.Utils; | ||
|
||
public class LegacySupportTests | ||
{ | ||
[Fact] | ||
public void SetProperties_Ok() | ||
{ | ||
var resilienceProperties = new ResilienceProperties(); | ||
var oldProps = resilienceProperties.Options; | ||
var newProps = new Dictionary<string, object?>(); | ||
|
||
resilienceProperties.SetProperties(newProps, out var oldProperties2); | ||
|
||
resilienceProperties.Options.Should().BeSameAs(newProps); | ||
oldProperties2.Should().BeSameAs(oldProps); | ||
} | ||
} |
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
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,35 @@ | ||
using System.ComponentModel; | ||
|
||
namespace Polly.Utils; | ||
|
||
/// <summary> | ||
/// Legacy support for older versions of Polly. | ||
/// </summary> | ||
/// <remarks> | ||
/// This class is used by the legacy Polly infrastructure and should not be used directly by user code. | ||
/// </remarks> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public static class LegacySupport | ||
{ | ||
/// <summary> | ||
/// Changes the underlying properties of a <see cref="ResilienceProperties"/> instance. | ||
/// </summary> | ||
/// <param name="resilienceProperties">The resilience properties.</param> | ||
/// <param name="properties">The properties to use.</param> | ||
/// <param name="oldProperties">The old properties used by <paramref name="resilienceProperties"/>.</param> | ||
/// <remarks> | ||
/// This method is used by the legacy Polly infrastructure and should not be used directly by user code. | ||
/// </remarks> | ||
[EditorBrowsable(EditorBrowsableState.Never)] | ||
public static void SetProperties( | ||
this ResilienceProperties resilienceProperties, | ||
IDictionary<string, object?> properties, | ||
out IDictionary<string, object?> oldProperties) | ||
{ | ||
Guard.NotNull(resilienceProperties); | ||
Guard.NotNull(properties); | ||
|
||
oldProperties = resilienceProperties.Options; | ||
resilienceProperties.Options = properties; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,42 +1,26 @@ | ||
using Polly.Utils; | ||
|
||
namespace Polly.Utilities.Wrappers; | ||
|
||
internal static class ResilienceContextFactory | ||
{ | ||
public static readonly ResiliencePropertyKey<Context> ContextKey = new("Polly.Legacy.Context"); | ||
|
||
public static ResilienceContext Create(Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) | ||
public static ResilienceContext Create( | ||
Context context, | ||
CancellationToken cancellationToken, | ||
bool continueOnCapturedContext, | ||
out IDictionary<string, object> oldProperties) | ||
{ | ||
var resilienceContext = ResilienceContext.Get(); | ||
resilienceContext.CancellationToken = cancellationToken; | ||
resilienceContext.ContinueOnCapturedContext = continueOnCapturedContext; | ||
|
||
foreach (var pair in context) | ||
{ | ||
var props = (IDictionary<string, object>)resilienceContext.Properties; | ||
props.Add(pair.Key, pair.Value); | ||
} | ||
|
||
resilienceContext.Properties.Set(ContextKey, context); | ||
resilienceContext.Properties.SetProperties(context, out oldProperties); | ||
|
||
return resilienceContext; | ||
} | ||
|
||
public static void Restore(ResilienceContext context) | ||
public static void Cleanup(ResilienceContext resilienceContext, IDictionary<string, object> oldProperties) | ||
{ | ||
var originalContext = context.GetContext(); | ||
|
||
foreach (var pair in context.Properties) | ||
{ | ||
if (pair.Key == ContextKey.Key) | ||
{ | ||
continue; | ||
} | ||
|
||
originalContext[pair.Key] = pair.Value; | ||
} | ||
|
||
ResilienceContext.Return(context); | ||
resilienceContext.Properties.SetProperties(oldProperties, out _); | ||
ResilienceContext.Return(resilienceContext); | ||
} | ||
|
||
public static Context GetContext(this ResilienceContext resilienceContext) => resilienceContext.Properties.GetValue(ContextKey, null!); | ||
} |
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
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
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
Oops, something went wrong.
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.
Wow - that's a lot!
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.
Yup, there is a resilience context lookup, lambda conversion, and bunch of other stuff. It really adds up.