Repository navigation
Avoid duplicate header parsing during JWT decoding - #543
Merged
Merged
Conversation
Assisted-By: devx/dcd17996-cea9-431c-837c-66a5b73abb5e
Assisted-By: devx/dcd17996-cea9-431c-837c-66a5b73abb5e
benni-rogge
marked this pull request as ready for review
September 18, 2026 14:00
arckoor
reviewed
Sep 18, 2026
arckoor
self-requested a review
September 23, 2026 18:19
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
Split each JWT and parse its header only once in
decode. Reuse that header for provider selection, signature verification, and the returned token data. Remove the now-redundant private helper. Algorithm checks, signature verification, claims validation, and the public API remain unchanged.The benchmark-only first commit fixes the decode fixture to contain matching claims and a valid expiration. It checks successful decoding, adds custom-header decode coverage, and gives encode cases distinct names. The same corrected workloads were used for both measurements.
Benchmark evidence
Criterion 0.8.2, 100 samples per case, 3-second warm-up, 5-second measurement. Apple M5 Pro, macOS arm64, rustc 1.98.1. Baseline source:
4c0ae752e9ac, with the benchmark corrections applied before measuring.Mean wall-clock time per successful HS256 decode:
rust_cryptorust_cryptoaws_lc_rsaws_lc_rsThese are four measurements of the same optimization, not accumulated gains. Every confidence interval clears 10%. Results apply to the small HS256 tokens in this benchmark, not all algorithms or payload sizes.
The unchanged encode implementation served as a control: mean timings ranged from 2.6% faster to 1.2% slower.
Reproduce
Run the baseline commands at the benchmark-only first commit, then the comparisons at the PR head. Preserve the generated
Cargo.lockandtarget/between runs.Verification
cargo fmt --check: passed.cargo clippy --locked --all-targets --features <backend> -- -D warnings: passed for both backends.cargo test --locked --features <backend>: 108 tests passed for each backend.cargo test --locked --no-default-features --features <backend>: 86 tests passed for each backend.Here
<backend>isrust_cryptooraws_lc_rs. No-default-feature tests emit unused-import and dead-code warnings in untouched test code. The MSRV/nightly/Wasm matrix was not run locally.Prepared with AI assistance; all reported benchmarks and checks were executed locally.