From 206792539ca0dd5f5a2de319d21422bb577bf32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gurhem?= Date: Fri, 3 Feb 2023 13:50:05 +0100 Subject: [PATCH] perf: avoid making copies when using gRPC ByteStrings --- .../ArmoniK.Api.Client/Submitter/SubmitterClientExt.cs | 4 ++-- packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs | 6 +++--- .../ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/csharp/ArmoniK.Api.Client/Submitter/SubmitterClientExt.cs b/packages/csharp/ArmoniK.Api.Client/Submitter/SubmitterClientExt.cs index c4a07586c..1d9f8c897 100644 --- a/packages/csharp/ArmoniK.Api.Client/Submitter/SubmitterClientExt.cs +++ b/packages/csharp/ArmoniK.Api.Client/Submitter/SubmitterClientExt.cs @@ -205,8 +205,8 @@ private static async IAsyncEnumerable ToRequestStream(th { TaskPayload = new DataChunk { - Data = ByteString.CopyFrom(taskRequest.Payload.Span.Slice(start, - chunkSize)), + Data = UnsafeByteOperations.UnsafeWrap(taskRequest.Payload.Memory.Slice(start, + chunkSize)), }, }; diff --git a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs index a11cfb1e6..0a908a18a 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs @@ -162,9 +162,9 @@ await stream.RequestStream.WriteAsync(new Result CommunicationToken = Token, Data = new DataChunk { - Data = ByteString.CopyFrom(data.AsMemory() - .Span.Slice(start, - chunkSize)), + Data = UnsafeByteOperations.UnsafeWrap(data.AsMemory() + .Slice(start, + chunkSize)), }, }) .ConfigureAwait(false); diff --git a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs index 586ee9a5b..dc17ed174 100644 --- a/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs +++ b/packages/csharp/ArmoniK.Api.Worker/Worker/TaskRequestExtensions.cs @@ -127,8 +127,8 @@ public static IEnumerable ToRequestStream(this TaskRequest ta CommunicationToken = token, TaskPayload = new DataChunk { - Data = ByteString.CopyFrom(taskRequest.Payload.Span.Slice(start, - chunkSize)), + Data = UnsafeByteOperations.UnsafeWrap(taskRequest.Payload.Memory.Slice(start, + chunkSize)), }, };