diff options
author | 2017-11-17 20:02:31 +0100 | |
---|---|---|
committer | 2017-11-21 07:32:57 +0100 | |
commit | 9a244d61d4a0b2bbe775041b5ce63c1df6a97e37 (patch) | |
tree | ef0170a4fcfc839b8bb139d5549dd60b95ab91da /src/csharp/Grpc.Microbenchmarks | |
parent | 2bc15ca776ab332768f9efaa6f935d969582da17 (diff) |
avoid unnecessary allocation in completion registry
Diffstat (limited to 'src/csharp/Grpc.Microbenchmarks')
-rw-r--r-- | src/csharp/Grpc.Microbenchmarks/CompletionRegistryBenchmark.cs | 12 | ||||
-rw-r--r-- | src/csharp/Grpc.Microbenchmarks/SendMessageBenchmark.cs | 2 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/csharp/Grpc.Microbenchmarks/CompletionRegistryBenchmark.cs b/src/csharp/Grpc.Microbenchmarks/CompletionRegistryBenchmark.cs index 810de119a8..0e2fb070f1 100644 --- a/src/csharp/Grpc.Microbenchmarks/CompletionRegistryBenchmark.cs +++ b/src/csharp/Grpc.Microbenchmarks/CompletionRegistryBenchmark.cs @@ -52,18 +52,26 @@ namespace Grpc.Microbenchmarks { var completionRegistry = new CompletionRegistry(environment); var ctx = BatchContextSafeHandle.Create(); - var completionDelegate = new OpCompletionDelegate((success) => {}); var stopwatch = Stopwatch.StartNew(); for (int i = 0; i < iterations; i++) { - completionRegistry.Register(ctx.DangerousGetHandle(), completionDelegate); + completionRegistry.Register(ctx.Handle, ctx); var callback = completionRegistry.Extract(completionRegistry.LastRegisteredKey); + // NOTE: we are not calling the callback to avoid disposing ctx. } stopwatch.Stop(); Console.WriteLine("Elapsed millis: " + stopwatch.ElapsedMilliseconds); ctx.Dispose(); } + + private class NopCompletionCallback : IOpCompletionCallback + { + public void OnComplete(bool success) + { + + } + } } } diff --git a/src/csharp/Grpc.Microbenchmarks/SendMessageBenchmark.cs b/src/csharp/Grpc.Microbenchmarks/SendMessageBenchmark.cs index de67874580..6a8a29d770 100644 --- a/src/csharp/Grpc.Microbenchmarks/SendMessageBenchmark.cs +++ b/src/csharp/Grpc.Microbenchmarks/SendMessageBenchmark.cs @@ -68,7 +68,7 @@ namespace Grpc.Microbenchmarks { call.StartSendMessage(sendCompletionHandler, payload, writeFlags, false); var callback = completionRegistry.Extract(completionRegistry.LastRegisteredKey); - callback(true); + callback.OnComplete(true); } stopwatch.Stop(); Console.WriteLine("Elapsed millis: " + stopwatch.ElapsedMilliseconds); |