Skip to content

Commit

Permalink
[Benchmarks] Nullabe (#5875)
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Kiełkowicz <[email protected]>
Co-authored-by: Mikel Blanchard <[email protected]>
  • Loading branch information
3 people authored Oct 4, 2024
1 parent 25d99a5 commit 02f4b2d
Show file tree
Hide file tree
Showing 23 changed files with 210 additions and 215 deletions.
3 changes: 0 additions & 3 deletions test/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>$(TargetFrameworksForTests)</TargetFrameworks>

<!-- this is temporary. will remove in future PR. -->
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ public class TraceContextPropagatorBenchmarks
return [];
};

private Dictionary<string, string> headers;

[Params(true, false)]
public bool LongListMember { get; set; }

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

public Dictionary<string, string> Headers => this.headers;
public Dictionary<string, string>? Headers { get; private set; }

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

this.headers = new Dictionary<string, string>
this.Headers = new Dictionary<string, string>
{
{ TraceParent, $"00-{TraceId}-{SpanId}-01" },
{ TraceState, traceState },
};
}

[Benchmark(Baseline = true)]
public void Extract() => _ = TraceContextPropagator!.Extract(default, this.headers, Getter);
public void Extract() => _ = TraceContextPropagator!.Extract(default, this.Headers!, Getter);
}
2 changes: 1 addition & 1 deletion test/Benchmarks/EventSourceBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void EventWithIdAllocation()
activity.Start();
activity.Stop();

OpenTelemetrySdkEventSource.Log.ActivityStarted(activity.OperationName, activity.Id);
OpenTelemetrySdkEventSource.Log.ActivityStarted(activity.OperationName, activity.Id!);
}

[Benchmark]
Expand Down
14 changes: 7 additions & 7 deletions test/Benchmarks/Exporter/OtlpGrpcExporterBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace Benchmarks.Exporter;

public class OtlpGrpcExporterBenchmarks
{
private OtlpTraceExporter exporter;
private Activity activity;
private CircularBuffer<Activity> activityBatch;
private OtlpTraceExporter? exporter;
private Activity? activity;
private CircularBuffer<Activity>? activityBatch;

[Params(1, 10, 100)]
public int NumberOfBatches { get; set; }
Expand All @@ -45,8 +45,8 @@ public void GlobalSetup()
[GlobalCleanup]
public void GlobalCleanup()
{
this.exporter.Shutdown();
this.exporter.Dispose();
this.exporter?.Shutdown();
this.exporter?.Dispose();
}

[Benchmark]
Expand All @@ -56,10 +56,10 @@ public void OtlpExporter_Batching()
{
for (int c = 0; c < this.NumberOfSpans; c++)
{
this.activityBatch.Add(this.activity);
this.activityBatch!.Add(this.activity!);
}

this.exporter.Export(new Batch<Activity>(this.activityBatch, this.NumberOfSpans));
this.exporter!.Export(new Batch<Activity>(this.activityBatch!, this.NumberOfSpans));
}
}
}
20 changes: 10 additions & 10 deletions test/Benchmarks/Exporter/OtlpHttpExporterBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace Benchmarks.Exporter;
public class OtlpHttpExporterBenchmarks
{
private readonly byte[] buffer = new byte[1024 * 1024];
private IDisposable server;
private string serverHost;
private IDisposable? server;
private string? serverHost;
private int serverPort;
private OtlpTraceExporter exporter;
private Activity activity;
private CircularBuffer<Activity> activityBatch;
private OtlpTraceExporter? exporter;
private Activity? activity;
private CircularBuffer<Activity>? activityBatch;

[Params(1, 10, 100)]
public int NumberOfBatches { get; set; }
Expand Down Expand Up @@ -73,9 +73,9 @@ public void GlobalSetup()
[GlobalCleanup]
public void GlobalCleanup()
{
this.exporter.Shutdown();
this.exporter.Dispose();
this.server.Dispose();
this.exporter?.Shutdown();
this.exporter?.Dispose();
this.server?.Dispose();
}

[Benchmark]
Expand All @@ -85,10 +85,10 @@ public void OtlpExporter_Batching()
{
for (int c = 0; c < this.NumberOfSpans; c++)
{
this.activityBatch.Add(this.activity);
this.activityBatch!.Add(this.activity!);
}

this.exporter.Export(new Batch<Activity>(this.activityBatch, this.NumberOfSpans));
this.exporter!.Export(new Batch<Activity>(this.activityBatch!, this.NumberOfSpans));
}
}
}
28 changes: 14 additions & 14 deletions test/Benchmarks/Exporter/OtlpLogExporterBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ namespace Benchmarks.Exporter;

public class OtlpLogExporterBenchmarks
{
private OtlpLogExporter exporter;
private LogRecord logRecord;
private CircularBuffer<LogRecord> logRecordBatch;
private OtlpLogExporter? exporter;
private LogRecord? logRecord;
private CircularBuffer<LogRecord>? logRecordBatch;

private IHost host;
private IDisposable server;
private string serverHost;
private IHost? host;
private IDisposable? server;
private string? serverHost;
private int serverPort;

[GlobalSetup(Target = nameof(OtlpLogExporter_Grpc))]
Expand Down Expand Up @@ -103,29 +103,29 @@ public void GlobalSetupHttp()
[GlobalCleanup(Target = nameof(OtlpLogExporter_Grpc))]
public void GlobalCleanupGrpc()
{
this.exporter.Shutdown();
this.exporter.Dispose();
this.host.Dispose();
this.exporter?.Shutdown();
this.exporter?.Dispose();
this.host?.Dispose();
}

[GlobalCleanup(Target = nameof(OtlpLogExporter_Http))]
public void GlobalCleanupHttp()
{
this.exporter.Shutdown();
this.exporter.Dispose();
this.server.Dispose();
this.exporter?.Shutdown();
this.exporter?.Dispose();
this.server?.Dispose();
}

[Benchmark]
public void OtlpLogExporter_Http()
{
this.exporter.Export(new Batch<LogRecord>(this.logRecordBatch, 1));
this.exporter!.Export(new Batch<LogRecord>(this.logRecordBatch!, 1));
}

[Benchmark]
public void OtlpLogExporter_Grpc()
{
this.exporter.Export(new Batch<LogRecord>(this.logRecordBatch, 1));
this.exporter!.Export(new Batch<LogRecord>(this.logRecordBatch!, 1));
}

private sealed class MockLogService : OtlpCollector.LogsService.LogsServiceBase
Expand Down
32 changes: 16 additions & 16 deletions test/Benchmarks/Exporter/OtlpTraceExporterBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ namespace Benchmarks.Exporter;

public class OtlpTraceExporterBenchmarks
{
private OtlpTraceExporter exporter;
private Activity activity;
private CircularBuffer<Activity> activityBatch;
private OtlpTraceExporter? exporter;
private Activity? activity;
private CircularBuffer<Activity>? activityBatch;

private IHost host;
private IDisposable server;
private string serverHost;
private IHost? host;
private IDisposable? server;
private string? serverHost;
private int serverPort;

[GlobalSetup(Target = nameof(OtlpTraceExporter_Grpc))]
Expand Down Expand Up @@ -103,31 +103,31 @@ public void GlobalSetupHttp()
[GlobalCleanup(Target = nameof(OtlpTraceExporter_Grpc))]
public void GlobalCleanupGrpc()
{
this.exporter.Shutdown();
this.exporter.Dispose();
this.activity.Dispose();
this.host.Dispose();
this.exporter?.Shutdown();
this.exporter?.Dispose();
this.activity?.Dispose();
this.host?.Dispose();
}

[GlobalCleanup(Target = nameof(OtlpTraceExporter_Http))]
public void GlobalCleanupHttp()
{
this.exporter.Shutdown();
this.exporter.Dispose();
this.server.Dispose();
this.activity.Dispose();
this.exporter?.Shutdown();
this.exporter?.Dispose();
this.server?.Dispose();
this.activity?.Dispose();
}

[Benchmark]
public void OtlpTraceExporter_Http()
{
this.exporter.Export(new Batch<Activity>(this.activityBatch, 1));
this.exporter!.Export(new Batch<Activity>(this.activityBatch!, 1));
}

[Benchmark]
public void OtlpTraceExporter_Grpc()
{
this.exporter.Export(new Batch<Activity>(this.activityBatch, 1));
this.exporter!.Export(new Batch<Activity>(this.activityBatch!, 1));
}

private sealed class MockTraceService : OtlpCollector.TraceService.TraceServiceBase
Expand Down
6 changes: 3 additions & 3 deletions test/Benchmarks/Exporter/PrometheusSerializerBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class PrometheusSerializerBenchmarks
{
private readonly List<Metric> metrics = new();
private readonly byte[] buffer = new byte[85000];
private Meter meter;
private MeterProvider meterProvider;
private Meter? meter;
private MeterProvider? meterProvider;
private Dictionary<Metric, PrometheusMetric> cache = new Dictionary<Metric, PrometheusMetric>();

[Params(1, 1000, 10000)]
Expand Down Expand Up @@ -45,7 +45,7 @@ public void GlobalSetup()
public void GlobalCleanup()
{
this.meter?.Dispose();
this.meterProvider.Dispose();
this.meterProvider?.Dispose();
}

// TODO: this has a dependency on https://github.com/open-telemetry/opentelemetry-dotnet/issues/2361
Expand Down
14 changes: 7 additions & 7 deletions test/Benchmarks/Exporter/ZipkinExporterBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace Benchmarks.Exporter;
public class ZipkinExporterBenchmarks
{
private readonly byte[] buffer = new byte[4096];
private Activity activity;
private CircularBuffer<Activity> activityBatch;
private IDisposable server;
private string serverHost;
private Activity? activity;
private CircularBuffer<Activity>? activityBatch;
private IDisposable? server;
private string? serverHost;
private int serverPort;

[Params(1, 10, 100)]
Expand Down Expand Up @@ -60,7 +60,7 @@ public void GlobalSetup()
[GlobalCleanup]
public void GlobalCleanup()
{
this.server.Dispose();
this.server?.Dispose();
}

[Benchmark]
Expand All @@ -76,10 +76,10 @@ public void ZipkinExporter_Batching()
{
for (int c = 0; c < this.NumberOfSpans; c++)
{
this.activityBatch.Add(this.activity);
this.activityBatch!.Add(this.activity!);
}

exporter.Export(new Batch<Activity>(this.activityBatch, this.NumberOfSpans));
exporter.Export(new Batch<Activity>(this.activityBatch!, this.NumberOfSpans));
}

exporter.Shutdown();
Expand Down
10 changes: 5 additions & 5 deletions test/Benchmarks/Helper/ActivityHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public static Activity CreateTestActivity()
new ActivityEvent(
"Event1",
eventTimestamp,
new ActivityTagsCollection(new Dictionary<string, object>
new ActivityTagsCollection(new Dictionary<string, object?>
{
{ "key", "value" },
})),
new ActivityEvent(
"Event2",
eventTimestamp,
new ActivityTagsCollection(new Dictionary<string, object>
new ActivityTagsCollection(new Dictionary<string, object?>
{
{ "key", "value" },
})),
Expand All @@ -48,7 +48,7 @@ public static Activity CreateTestActivity()

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

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

foreach (var evnt in events)
{
activity.AddEvent(evnt);
activity!.AddEvent(evnt);
}

activity.SetEndTime(endTimestamp);
activity!.SetEndTime(endTimestamp);
activity.Stop();

return activity;
Expand Down
2 changes: 1 addition & 1 deletion test/Benchmarks/Logs/LogScopeBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public LogScopeBenchmarks()
[Benchmark]
public void ForEachScope()
{
this.logRecord.ForEachScope(this.callback, null);
this.logRecord.ForEachScope(this.callback!, null);
}
}
Loading

0 comments on commit 02f4b2d

Please sign in to comment.