Skip to content

Commit

Permalink
perf: avoid making copies when using gRPC ByteStrings
Browse files Browse the repository at this point in the history
  • Loading branch information
aneojgurhem committed Feb 3, 2023
1 parent 5ac4f11 commit 2067925
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ private static async IAsyncEnumerable<CreateLargeTaskRequest> ToRequestStream(th
{
TaskPayload = new DataChunk
{
Data = ByteString.CopyFrom(taskRequest.Payload.Span.Slice(start,
chunkSize)),
Data = UnsafeByteOperations.UnsafeWrap(taskRequest.Payload.Memory.Slice(start,
chunkSize)),
},
};

Expand Down
6 changes: 3 additions & 3 deletions packages/csharp/ArmoniK.Api.Worker/Worker/TaskHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public static IEnumerable<CreateTaskRequest> 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)),
},
};

Expand Down

0 comments on commit 2067925

Please sign in to comment.