Skip to content

perf(persona): single-allocation content_hash_sha256 (#1145)#1147

Merged
joelteply merged 1 commit into
canaryfrom
perf/content-hash-single-alloc
May 14, 2026
Merged

perf(persona): single-allocation content_hash_sha256 (#1145)#1147
joelteply merged 1 commit into
canaryfrom
perf/content-hash-single-alloc

Conversation

@joelteply
Copy link
Copy Markdown
Contributor

Summary

Replace format!() per byte with write!() into the pre-allocated buffer in content_hash_sha256. Previous code allocated 32 small Strings per hash; now allocates exactly one String for the whole output. Same correctness, same canonical "sha256:<hex>" output.

Hot path: content_hash_sha256 runs once per inbox message at admission time. With multi-persona load + AIRC msg flood, the per-byte allocation shows up as GC churn on the heap.

Card

continuum#1145.

Origin

Spotted by claude-tab-2 in their post-merge review of continuum#1143 (PR-3 of #1121). Fast follow-up rather than bundling into PR-4.

Validation

$ cargo test -p continuum-core --features metal,accelerate persona::inbox_admission
test result: ok. 16 passed; 0 failed; 0 ignored

npm run build:ts clean. Hooks ran without --no-verify.

Note

Force-pushed once after correcting an --amend-clobbered commit attempt. Branch is fresh, no prior PR opened, no other contributors. canary upstream + codex's #1144 unaffected. Lesson saved to memory; won't recur.

🤖 Generated with Claude Code

…1145)

Replaces `format!()` per byte with `write!()` into the pre-allocated
buffer. Previous code allocated 32 small Strings per hash (one per
byte's `format!()` call); now allocates exactly one String for the
whole output.

Hot path: content_hash_sha256 runs once per inbox message at admission
time. With multi-persona load + AIRC msg flood, the per-byte allocation
shows up as GC churn on the heap.

Same correctness; same canonical "sha256:<hex>" output. 16/16 tests
green (persona::inbox_admission unchanged in scope).

Spotted by claude-tab-2 in their post-merge review of continuum#1143.

Card: continuum#1145.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@joelteply joelteply merged commit 99ffc47 into canary May 14, 2026
3 checks passed
@joelteply joelteply deleted the perf/content-hash-single-alloc branch May 14, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant