Skip to content

perf: avoid per-chunk byte[] copy in CryptifyClient.StoreChunkAsync#30

Merged
rubenhensen merged 1 commit into
mainfrom
perf/cryptify-chunk-zero-copy
May 28, 2026
Merged

perf: avoid per-chunk byte[] copy in CryptifyClient.StoreChunkAsync#30
rubenhensen merged 1 commit into
mainfrom
perf/cryptify-chunk-zero-copy

Conversation

@dobby-coder

@dobby-coder dobby-coder Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

StoreChunkAsync was allocating a fresh byte[] per chunk and Buffer.BlockCopy'ing the payload in, just to hand it off to ByteArrayContent. For a 100 MB upload at the 1 MB chunk size that's 100 redundant 1 MB allocations on top of the original buffer.

Switched to the ByteArrayContent(byte[] buffer, int offset, int count) overload, which wraps the source slice in place (no copy). No call-site changes; UploadAsync already passes the source buffer plus offset/end.

Test plan

  • dotnet build succeeds on net8.0 and net10.0.
  • dotnet test: 22/22 pass on net10.0 (existing suite doesn't cover CryptifyClient; this is a zero-behaviour-change perf tweak).

Closes #27

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
@dobby-coder dobby-coder Bot requested a review from rubenhensen May 27, 2026 23:35
@dobby-coder

dobby-coder Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

RULES check: edited the PR body to drop two em-dashes flagged by the writing-rules memory (rule #40, "the ChatGPT dash" — used where commas or parens would be normal). Replaced "in place — no copy" with "in place (no copy)" and dotnet test — 22/22 with dotnet test: 22/22. No code changes.

@rubenhensen rubenhensen merged commit a3762d0 into main May 28, 2026
3 checks passed
@rubenhensen rubenhensen deleted the perf/cryptify-chunk-zero-copy branch May 28, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CryptifyClient.StoreChunkAsync allocates a copy of every chunk

1 participant