perf(rsema1d): reuse SHA256 hasher in coefficient derivation#7064
Merged
perf(rsema1d): reuse SHA256 hasher in coefficient derivation#7064
Conversation
Reuse a single sha256 hasher with Reset() between iterations in deriveCoefficients instead of calling sha256.Sum256() per symbol. This avoids re-initializing the internal digest state from scratch each time, yielding ~12% speedup on the SHA256 portion of coefficient derivation. Also add verify_breakdown_bench_test.go that isolates each component of VerifyRowWithContext for profiling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
Member
|
Reminded me of https://github.com/celestiaorg/rsema1d-private/pull/16/ |
Handle unchecked error returns from rand.Read and merkle.ComputeRootFromProof, and fix gofumpt comment alignment to satisfy CI golangci-lint checks. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wondertan
reviewed
Apr 14, 2026
Existing BenchmarkDeriveCoefficients already covers the optimized path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wondertan
approved these changes
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reuses a single
sha256hasher withReset()between iterations inderiveCoefficients, instead of callingsha256.Sum256()(which re-initializes from scratch each time).Motivation
Benchmarking the verification hot path shows
deriveCoefficientsis the most expensive component ofVerifyRowWithContext— 65% of total time for 128MB blobs. It calls SHA256 once per GF16 symbol: 65,536 hashes for 128KB rows.Component breakdown (128MB blob, per-row):
Reusing the hasher saves ~12% on the SHA256 portion (~0.6ms for 128MB blobs).
Changes
pkg/rsema1d/commitment.go:deriveCoefficientsnow usesh.Reset()+h.Write()+h.Sum(digest[:0])instead ofsha256.Sum256()pkg/rsema1d/verify_breakdown_bench_test.go: New benchmark breaking down each component ofVerifyRowWithContextat 1MB/8MB/128MB blob sizesBenchmarks
Note: a further 55% reduction is possible by deriving 2 coefficients per hash (using both 16-byte halves independently instead of XOR-folding), but that requires a protocol/spec change.
Test plan
go test ./pkg/rsema1d/...passesCloses https://linear.app/celestia/issue/PROTOCO-1497
🤖 Generated with Claude Code