-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added memory optimisations for GetLastActiveSpan (#2642)
- Loading branch information
1 parent
cecb99d
commit 5cb67de
Showing
4 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
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
17 changes: 17 additions & 0 deletions
17
...t.Artifacts/results/Sentry.Benchmarks.LastActiveSpanBenchmarks-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,17 @@ | ||
``` ini | ||
|
||
BenchmarkDotNet=v0.13.5, OS=macOS Ventura 13.5.2 (22G91) [Darwin 22.6.0] | ||
Apple M1, 1 CPU, 8 logical and 8 physical cores | ||
.NET SDK=7.0.306 | ||
[Host] : .NET 6.0.19 (6.0.1923.31806), Arm64 RyuJIT AdvSIMD | ||
ShortRun : .NET 6.0.19 (6.0.1923.31806), Arm64 RyuJIT AdvSIMD | ||
|
||
Job=ShortRun IterationCount=3 LaunchCount=1 | ||
WarmupCount=3 | ||
|
||
``` | ||
| Method | SpanCount | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | | ||
|-------------------------------- |---------- |----------:|------------:|----------:|--------:|--------:|----------:| | ||
| **'Create spans for scope access'** | **1** | **32.34 μs** | **26.58 μs** | **1.457 μs** | **4.7607** | **1.5259** | **16.68 KB** | | ||
| **'Create spans for scope access'** | **10** | **101.28 μs** | **239.09 μs** | **13.105 μs** | **9.1553** | **2.5635** | **39.21 KB** | | ||
| **'Create spans for scope access'** | **100** | **628.84 μs** | **1,267.56 μs** | **69.479 μs** | **59.5703** | **18.5547** | **266.14 KB** | |
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,57 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using Perfolizer.Mathematics.Randomization; | ||
|
||
namespace Sentry.Benchmarks; | ||
|
||
public class LastActiveSpanBenchmarks | ||
{ | ||
private const string Operation = "Operation"; | ||
private const string Name = "Name"; | ||
|
||
[Params(1, 10, 100)] | ||
public int SpanCount; | ||
|
||
private IDisposable _sdk; | ||
|
||
[GlobalSetup(Target = nameof(CreateScopedSpans))] | ||
public void EnabledSdk() => _sdk = SentrySdk.Init(Constants.ValidDsn); | ||
|
||
[GlobalCleanup(Target = nameof(CreateScopedSpans))] | ||
public void DisableDsk() => _sdk.Dispose(); | ||
|
||
[Benchmark(Description = "Create spans for scope access")] | ||
public void CreateScopedSpans() | ||
{ | ||
var transaction = SentrySdk.StartTransaction(Name, Operation); | ||
SentrySdk.WithScope(scope => | ||
{ | ||
scope.Transaction = transaction; | ||
for (var i = 0; i < SpanCount; i++) | ||
{ | ||
// Simulates a scenario where TransactionTracer.GetLastActiveSpan will be called frequently | ||
// See: https://github.com/getsentry/sentry-dotnet/blob/c2a31b4ead03da388c2db7fe07f290354aa51b9d/src/Sentry/Scope.cs#L567C1-L567C68 | ||
CallOneFunction(i); | ||
} | ||
}); | ||
transaction.Finish(); | ||
} | ||
|
||
private void CallOneFunction(int i) | ||
{ | ||
var span = SentrySdk.GetSpan()!.StartChild($"One Function {i}"); | ||
ThatCallsAnother(i); | ||
span.Finish(); | ||
} | ||
|
||
private void ThatCallsAnother(int i) | ||
{ | ||
var span = SentrySdk.GetSpan()!.StartChild($"Another Function {i}"); | ||
AndAnother($"Alternate Description {i}"); | ||
span.Finish(); | ||
} | ||
|
||
private void AndAnother(string description) | ||
{ | ||
SentrySdk.ConfigureScope(scope => scope.Span!.Description = description); | ||
} | ||
} |
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