Skip to content

Commit a3762d0

Browse files
perf: avoid per-chunk byte[] copy in CryptifyClient.StoreChunkAsync (#30)
Use the ByteArrayContent(buffer, offset, count) overload to slice the source array without copying, instead of allocating a fresh byte[] per chunk and BlockCopy'ing into it. For a 100 MB upload at the 1 MB chunk size this avoids 100 redundant 1 MB allocations on top of the original buffer. Closes #27 Co-authored-by: dobby-yivi-agent[bot] <275734547+dobby-yivi-agent[bot]@users.noreply.github.com>
1 parent 1480dce commit a3762d0

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

src/Api/CryptifyClient.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,9 @@ public async Task<string> UploadAsync(
8989
private async Task<string> StoreChunkAsync(
9090
string uuid, string token, byte[] data, int offset, int end, CancellationToken ct)
9191
{
92-
var chunk = new byte[end - offset];
93-
Buffer.BlockCopy(data, offset, chunk, 0, chunk.Length);
94-
9592
var request = new HttpRequestMessage(HttpMethod.Put, $"{_cryptifyUrl}/fileupload/{uuid}")
9693
{
97-
Content = new ByteArrayContent(chunk)
94+
Content = new ByteArrayContent(data, offset, end - offset)
9895
};
9996
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
10097
request.Content.Headers.Add("Content-Range", $"bytes {offset}-{end}/*");

0 commit comments

Comments
 (0)