Speed up initSecret on the seeded long-input path#28
Open
ajvengo wants to merge 1 commit into
Open
Conversation
Stride the secret offset directly (i += 16) instead of indexing groups (16*i), dropping the per-iteration multiply in the 192-byte secret derivation. This derivation runs on every HashSeed/HashStringSeed call for inputs longer than 240 bytes, and once per New/NewSeed/ResetSeed. Output is unchanged; TestVectorCompat and the seed vectors still pass. Measured on an Apple M4 Max (NEON), interleaved old/new runs, n=12: Fixed64/241/seed 16.13ns -> 15.68ns -2.82% Fixed64/512/seed 20.91ns -> 19.90ns -4.85% Fixed128/241/seed 17.70ns -> 17.49ns -1.19% Fixed128/512/seed 22.75ns -> 21.95ns -3.52% Unseeded paths are untouched and show no change (p > 0.05).
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.
What
initSecretderives the 192-byte custom secret by striding the offsetdirectly (
i += 16) instead of indexing 16-byte groups (16*i), whichdrops the per-iteration multiply. The output is byte-identical.
Why
This derivation runs on every
HashSeed/HashStringSeedcall forinputs longer than 240 bytes (the
>240branch inhashAnySeed/hashAny128Seed), and once perNew/NewSeed/ResetSeed. For seededinputs in the ~241–1024 B range it's a noticeable fixed cost on top of
the hash itself, so trimming it helps that band directly.
Benchmarks
Apple M4 Max (arm64/NEON), old vs new compiled as separate binaries and
run interleaved (old, new, old, new… ×12) so run-to-run drift cancels;
compared with
benchstat:Fixed64/241/seedFixed64/512/seedFixed128/241/seedFixed128/512/seedThe unseeded paths don't call
initSecret; their control benchmarks(
.../default) show no change (all p > 0.05), as expected. The gainshrinks for very large inputs as the fixed derivation cost amortizes away.
Correctness
go test ./...passes, includingTestVectorCompatand the seeded goldenvectors.
go vet(amd64/arm64/386-softfloat) andgofmtare clean.