Skip to content

Commit 02f4b2d

Browse files
ysolomchenkoKielekCodeBlanch
authored
[Benchmarks] Nullabe (open-telemetry#5875)
Co-authored-by: Piotr Kiełkowicz <[email protected]> Co-authored-by: Mikel Blanchard <[email protected]>
1 parent 25d99a5 commit 02f4b2d

23 files changed

+210
-215
lines changed

test/Benchmarks/Benchmarks.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>$(TargetFrameworksForTests)</TargetFrameworks>
6-
7-
<!-- this is temporary. will remove in future PR. -->
8-
<Nullable>disable</Nullable>
96
</PropertyGroup>
107

118
<ItemGroup>

test/Benchmarks/Context/Propagation/TraceContextPropagatorBenchmarks.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ public class TraceContextPropagatorBenchmarks
2626
return [];
2727
};
2828

29-
private Dictionary<string, string> headers;
30-
3129
[Params(true, false)]
3230
public bool LongListMember { get; set; }
3331

3432
[Params(0, 4, 32)]
3533
public int MembersCount { get; set; }
3634

37-
public Dictionary<string, string> Headers => this.headers;
35+
public Dictionary<string, string>? Headers { get; private set; }
3836

3937
[GlobalSetup]
4038
public void Setup()
@@ -60,13 +58,13 @@ public void Setup()
6058
traceState += i < this.MembersCount - 1 ? $"{listMember}," : listMember;
6159
}
6260

63-
this.headers = new Dictionary<string, string>
61+
this.Headers = new Dictionary<string, string>
6462
{
6563
{ TraceParent, $"00-{TraceId}-{SpanId}-01" },
6664
{ TraceState, traceState },
6765
};
6866
}
6967

7068
[Benchmark(Baseline = true)]
71-
public void Extract() => _ = TraceContextPropagator!.Extract(default, this.headers, Getter);
69+
public void Extract() => _ = TraceContextPropagator!.Extract(default, this.Headers!, Getter);
7270
}

test/Benchmarks/EventSourceBenchmarks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void EventWithIdAllocation()
1717
activity.Start();
1818
activity.Stop();
1919

20-
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity.OperationName, activity.Id);
20+
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity.OperationName, activity.Id!);
2121
}
2222

2323
[Benchmark]

test/Benchmarks/Exporter/OtlpGrpcExporterBenchmarks.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ namespace Benchmarks.Exporter;
1818

1919
public class OtlpGrpcExporterBenchmarks
2020
{
21-
private OtlpTraceExporter exporter;
22-
private Activity activity;
23-
private CircularBuffer<Activity> activityBatch;
21+
private OtlpTraceExporter? exporter;
22+
private Activity? activity;
23+
private CircularBuffer<Activity>? activityBatch;
2424

2525
[Params(1, 10, 100)]
2626
public int NumberOfBatches { get; set; }
@@ -45,8 +45,8 @@ public void GlobalSetup()
4545
[GlobalCleanup]
4646
public void GlobalCleanup()
4747
{
48-
this.exporter.Shutdown();
49-
this.exporter.Dispose();
48+
this.exporter?.Shutdown();
49+
this.exporter?.Dispose();
5050
}
5151

5252
[Benchmark]
@@ -56,10 +56,10 @@ public void OtlpExporter_Batching()
5656
{
5757
for (int c = 0; c < this.NumberOfSpans; c++)
5858
{
59-
this.activityBatch.Add(this.activity);
59+
this.activityBatch!.Add(this.activity!);
6060
}
6161

62-
this.exporter.Export(new Batch<Activity>(this.activityBatch, this.NumberOfSpans));
62+
this.exporter!.Export(new Batch<Activity>(this.activityBatch!, this.NumberOfSpans));
6363
}
6464
}
6565
}

test/Benchmarks/Exporter/OtlpHttpExporterBenchmarks.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ namespace Benchmarks.Exporter;
2020
public class OtlpHttpExporterBenchmarks
2121
{
2222
private readonly byte[] buffer = new byte[1024 * 1024];
23-
private IDisposable server;
24-
private string serverHost;
23+
private IDisposable? server;
24+
private string? serverHost;
2525
private int serverPort;
26-
private OtlpTraceExporter exporter;
27-
private Activity activity;
28-
private CircularBuffer<Activity> activityBatch;
26+
private OtlpTraceExporter? exporter;
27+
private Activity? activity;
28+
private CircularBuffer<Activity>? activityBatch;
2929

3030
[Params(1, 10, 100)]
3131
public int NumberOfBatches { get; set; }
@@ -73,9 +73,9 @@ public void GlobalSetup()
7373
[GlobalCleanup]
7474
public void GlobalCleanup()
7575
{
76-
this.exporter.Shutdown();
77-
this.exporter.Dispose();
78-
this.server.Dispose();
76+
this.exporter?.Shutdown();
77+
this.exporter?.Dispose();
78+
this.server?.Dispose();
7979
}
8080

8181
[Benchmark]
@@ -85,10 +85,10 @@ public void OtlpExporter_Batching()
8585
{
8686
for (int c = 0; c < this.NumberOfSpans; c++)
8787
{
88-
this.activityBatch.Add(this.activity);
88+
this.activityBatch!.Add(this.activity!);
8989
}
9090

91-
this.exporter.Export(new Batch<Activity>(this.activityBatch, this.NumberOfSpans));
91+
this.exporter!.Export(new Batch<Activity>(this.activityBatch!, this.NumberOfSpans));
9292
}
9393
}
9494
}

test/Benchmarks/Exporter/OtlpLogExporterBenchmarks.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ namespace Benchmarks.Exporter;
3636

3737
public class OtlpLogExporterBenchmarks
3838
{
39-
private OtlpLogExporter exporter;
40-
private LogRecord logRecord;
41-
private CircularBuffer<LogRecord> logRecordBatch;
39+
private OtlpLogExporter? exporter;
40+
private LogRecord? logRecord;
41+
private CircularBuffer<LogRecord>? logRecordBatch;
4242

43-
private IHost host;
44-
private IDisposable server;
45-
private string serverHost;
43+
private IHost? host;
44+
private IDisposable? server;
45+
private string? serverHost;
4646
private int serverPort;
4747

4848
[GlobalSetup(Target = nameof(OtlpLogExporter_Grpc))]
@@ -103,29 +103,29 @@ public void GlobalSetupHttp()
103103
[GlobalCleanup(Target = nameof(OtlpLogExporter_Grpc))]
104104
public void GlobalCleanupGrpc()
105105
{
106-
this.exporter.Shutdown();
107-
this.exporter.Dispose();
108-
this.host.Dispose();
106+
this.exporter?.Shutdown();
107+
this.exporter?.Dispose();
108+
this.host?.Dispose();
109109
}
110110

111111
[GlobalCleanup(Target = nameof(OtlpLogExporter_Http))]
112112
public void GlobalCleanupHttp()
113113
{
114-
this.exporter.Shutdown();
115-
this.exporter.Dispose();
116-
this.server.Dispose();
114+
this.exporter?.Shutdown();
115+
this.exporter?.Dispose();
116+
this.server?.Dispose();
117117
}
118118

119119
[Benchmark]
120120
public void OtlpLogExporter_Http()
121121
{
122-
this.exporter.Export(new Batch<LogRecord>(this.logRecordBatch, 1));
122+
this.exporter!.Export(new Batch<LogRecord>(this.logRecordBatch!, 1));
123123
}
124124

125125
[Benchmark]
126126
public void OtlpLogExporter_Grpc()
127127
{
128-
this.exporter.Export(new Batch<LogRecord>(this.logRecordBatch, 1));
128+
this.exporter!.Export(new Batch<LogRecord>(this.logRecordBatch!, 1));
129129
}
130130

131131
private sealed class MockLogService : OtlpCollector.LogsService.LogsServiceBase

test/Benchmarks/Exporter/OtlpTraceExporterBenchmarks.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ namespace Benchmarks.Exporter;
3636

3737
public class OtlpTraceExporterBenchmarks
3838
{
39-
private OtlpTraceExporter exporter;
40-
private Activity activity;
41-
private CircularBuffer<Activity> activityBatch;
39+
private OtlpTraceExporter? exporter;
40+
private Activity? activity;
41+
private CircularBuffer<Activity>? activityBatch;
4242

43-
private IHost host;
44-
private IDisposable server;
45-
private string serverHost;
43+
private IHost? host;
44+
private IDisposable? server;
45+
private string? serverHost;
4646
private int serverPort;
4747

4848
[GlobalSetup(Target = nameof(OtlpTraceExporter_Grpc))]
@@ -103,31 +103,31 @@ public void GlobalSetupHttp()
103103
[GlobalCleanup(Target = nameof(OtlpTraceExporter_Grpc))]
104104
public void GlobalCleanupGrpc()
105105
{
106-
this.exporter.Shutdown();
107-
this.exporter.Dispose();
108-
this.activity.Dispose();
109-
this.host.Dispose();
106+
this.exporter?.Shutdown();
107+
this.exporter?.Dispose();
108+
this.activity?.Dispose();
109+
this.host?.Dispose();
110110
}
111111

112112
[GlobalCleanup(Target = nameof(OtlpTraceExporter_Http))]
113113
public void GlobalCleanupHttp()
114114
{
115-
this.exporter.Shutdown();
116-
this.exporter.Dispose();
117-
this.server.Dispose();
118-
this.activity.Dispose();
115+
this.exporter?.Shutdown();
116+
this.exporter?.Dispose();
117+
this.server?.Dispose();
118+
this.activity?.Dispose();
119119
}
120120

121121
[Benchmark]
122122
public void OtlpTraceExporter_Http()
123123
{
124-
this.exporter.Export(new Batch<Activity>(this.activityBatch, 1));
124+
this.exporter!.Export(new Batch<Activity>(this.activityBatch!, 1));
125125
}
126126

127127
[Benchmark]
128128
public void OtlpTraceExporter_Grpc()
129129
{
130-
this.exporter.Export(new Batch<Activity>(this.activityBatch, 1));
130+
this.exporter!.Export(new Batch<Activity>(this.activityBatch!, 1));
131131
}
132132

133133
private sealed class MockTraceService : OtlpCollector.TraceService.TraceServiceBase

test/Benchmarks/Exporter/PrometheusSerializerBenchmarks.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class PrometheusSerializerBenchmarks
1414
{
1515
private readonly List<Metric> metrics = new();
1616
private readonly byte[] buffer = new byte[85000];
17-
private Meter meter;
18-
private MeterProvider meterProvider;
17+
private Meter? meter;
18+
private MeterProvider? meterProvider;
1919
private Dictionary<Metric, PrometheusMetric> cache = new Dictionary<Metric, PrometheusMetric>();
2020

2121
[Params(1, 1000, 10000)]
@@ -45,7 +45,7 @@ public void GlobalSetup()
4545
public void GlobalCleanup()
4646
{
4747
this.meter?.Dispose();
48-
this.meterProvider.Dispose();
48+
this.meterProvider?.Dispose();
4949
}
5050

5151
// TODO: this has a dependency on https://github.com/open-telemetry/opentelemetry-dotnet/issues/2361

test/Benchmarks/Exporter/ZipkinExporterBenchmarks.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ namespace Benchmarks.Exporter;
1919
public class ZipkinExporterBenchmarks
2020
{
2121
private readonly byte[] buffer = new byte[4096];
22-
private Activity activity;
23-
private CircularBuffer<Activity> activityBatch;
24-
private IDisposable server;
25-
private string serverHost;
22+
private Activity? activity;
23+
private CircularBuffer<Activity>? activityBatch;
24+
private IDisposable? server;
25+
private string? serverHost;
2626
private int serverPort;
2727

2828
[Params(1, 10, 100)]
@@ -60,7 +60,7 @@ public void GlobalSetup()
6060
[GlobalCleanup]
6161
public void GlobalCleanup()
6262
{
63-
this.server.Dispose();
63+
this.server?.Dispose();
6464
}
6565

6666
[Benchmark]
@@ -76,10 +76,10 @@ public void ZipkinExporter_Batching()
7676
{
7777
for (int c = 0; c < this.NumberOfSpans; c++)
7878
{
79-
this.activityBatch.Add(this.activity);
79+
this.activityBatch!.Add(this.activity!);
8080
}
8181

82-
exporter.Export(new Batch<Activity>(this.activityBatch, this.NumberOfSpans));
82+
exporter.Export(new Batch<Activity>(this.activityBatch!, this.NumberOfSpans));
8383
}
8484

8585
exporter.Shutdown();

test/Benchmarks/Helper/ActivityHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public static Activity CreateTestActivity()
3131
new ActivityEvent(
3232
"Event1",
3333
eventTimestamp,
34-
new ActivityTagsCollection(new Dictionary<string, object>
34+
new ActivityTagsCollection(new Dictionary<string, object?>
3535
{
3636
{ "key", "value" },
3737
})),
3838
new ActivityEvent(
3939
"Event2",
4040
eventTimestamp,
41-
new ActivityTagsCollection(new Dictionary<string, object>
41+
new ActivityTagsCollection(new Dictionary<string, object?>
4242
{
4343
{ "key", "value" },
4444
})),
@@ -48,7 +48,7 @@ public static Activity CreateTestActivity()
4848

4949
using var activitySource = new ActivitySource(nameof(CreateTestActivity));
5050

51-
var tags = attributes.Select(kvp => new KeyValuePair<string, object>(kvp.Key, kvp.Value.ToString()));
51+
var tags = attributes.Select(kvp => new KeyValuePair<string, object?>(kvp.Key, kvp.Value.ToString()));
5252
var links = new[]
5353
{
5454
new ActivityLink(new ActivityContext(
@@ -75,10 +75,10 @@ public static Activity CreateTestActivity()
7575

7676
foreach (var evnt in events)
7777
{
78-
activity.AddEvent(evnt);
78+
activity!.AddEvent(evnt);
7979
}
8080

81-
activity.SetEndTime(endTimestamp);
81+
activity!.SetEndTime(endTimestamp);
8282
activity.Stop();
8383

8484
return activity;

0 commit comments

Comments
 (0)