perf(blake2s): reduce allocations and CPU in CASM hash wrapper#3787
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3787 +/- ##
==========================================
- Coverage 75.34% 75.29% -0.05%
==========================================
Files 438 438
Lines 39528 39536 +8
==========================================
- Hits 29781 29770 -11
- Misses 7676 7695 +19
Partials 2071 2071 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Claude finished @ongyimeng's task in 2m 2s —— View job Review: PR #3787 — blake2s allocation/CPU reduction
Nicely scoped performance change. The refactor is correct — I verified each transformation against the original behavior:
I could not run nit (test coverage)The PR removes Consider preserving Summary
LGTM aside from the nit. |
|
Will add back TestUnsafeConversion based on the nit. |
|
Claude finished @ongyimeng's task in 1m 48s —— View job Re-review: PR #3787 — blake2s allocation/CPU reductionNew commit
The follow-up correctly resolves the prior nit. The rest of the change is unchanged from the previously-reviewed state and still holds (encoding is byte-identical, I couldn't run One remaining nitThe deleted Summary
Prior nit resolved. LGTM. |

Summary
This reduces allocations and CPU in Juno's wrapper around
Blake2s, which is used when locally recomputing CASMHashVersionV2hashes. The underlyinggolang.org/x/crypto/blake2simplementation is unchanged.Closes #3751
Changes
[]uint32allocation and copy.Bits()once per felt and compare limbs directly against the2^63threshold, avoiding repeated Montgomery conversions fromCmp.blake2s.Sum256API instead ofNew256/Write/Sumfor one-shot hashing.BenchmarkCasmClassHashV2for the CASM V2 recomputation path.Results
Measured with
benchstat(n=6) on a real mainnet class-heavy fixture: block 10727585, ~25k bytecode felts.The time baseline is noisier than memory and allocations, but the direction and allocation reduction are stable.
Testing
hash_test.gocover the encoding boundaries (zero,2^63, max uint64, mixed small/large values).class_test.gocoverage verifiesHashVersionV2output against an expected compiled class hash.utils_test.gois removed because it only tested private helpers that no longer exist, behavior is still covered by the public hash vectors.