perf: use static strings for static error messages and avoid needless clones#27
Open
DXist wants to merge 5 commits into
Open
perf: use static strings for static error messages and avoid needless clones#27DXist wants to merge 5 commits into
DXist wants to merge 5 commits into
Conversation
Author
|
@junkurihara , I rewrote the interface to pass owned signature_params to avoid clones, got ~12% improvement over the baseline code: |
Author
|
I removed intermediate allocations in |
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.
This PR made perf-related changes:
Cow<'static, str>for static error messagesextract_signatures_innerhelperalgclone when only reference is used downstreamfield_valuesto avoid intermediateto_veccloneswap_removeinstead ofget+cloneSignatureBase::try_newavoids a clone ofcomponent_lines.as_field_valuetoCow<'static, str>to avoid intermediate allocation forHttpMessageComponentValueInner::Stringvariant.Stylistic change:
as_field_valueis renamed toto_field_valuebecause conversion is potentially not cheap due to allocation forKeyValuecase.To measure the effect of the clone-related changes, I also added
noncrypto.rsbenches module with two benches related toSignatureBaseconstruction andSignatureBaseconstruction.I ran the benches before the perf changes and saved the results as my baseline.
Then I ran the benches after the perf changes and got ~8% improvement.
cargo bench -p httpsig --bench noncrypto -- --baseline=baseline Compiling httpsig v0.0.24 (/Users/rinatshigapov/workspace/httpsig-rs/httpsig) Finished `bench` profile [optimized] target(s) in 17.12s Running benches/noncrypto.rs (target/release/deps/noncrypto-33899b8172d49ef8) Gnuplot not found, using plotters backend sig base try_new time: [2.1496 µs 2.1759 µs 2.2058 µs] change: [−9.1410% −8.5174% −7.8754%] (p = 0.00 < 0.05) Performance has improved. Found 4 outliers among 100 measurements (4.00%) 4 (4.00%) high severesig base try_parse time: [2.5472 µs 2.5860 µs 2.6457 µs]
change: [−8.4396% −7.5125% −6.3287%] (p = 0.00 < 0.05)
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
3 (3.00%) high mild
3 (3.00%) high severe
It's also possible to avoid cloning of
signature_params: &HttpSignatureParaminHttpSignatureBase::try_newand accept owned params inset_message_signatures. If the signer uses a template value forHttpSignatureParam, the cloning cost could be decreased by usingcompact_str::CompactString.I tried locally to accept the owned
signature_paramsandswap_removethem from the parsed HeadersMap.The improvement over the baseline became ~14-15%.
cargo bench -p httpsig --bench noncrypto -- --baseline=baseline Compiling httpsig v0.0.24 (/Users/rinatshigapov/workspace/httpsig-rs/httpsig) Finished `bench` profile [optimized] target(s) in 17.10s Running benches/noncrypto.rs (target/release/deps/noncrypto-33899b8172d49ef8) Gnuplot not found, using plotters backend sig base try_new time: [1.9997 µs 2.0062 µs 2.0133 µs] change: [−15.587% −15.071% −14.630%] (p = 0.00 < 0.05) Performance has improved. Found 4 outliers among 100 measurements (4.00%) 3 (3.00%) high mild 1 (1.00%) high severesig base try_parse time: [2.3689 µs 2.3805 µs 2.3924 µs]
change: [−14.595% −13.957% −13.337%] (p = 0.00 < 0.05)
Performance has improved.
Found 6 outliers among 100 measurements (6.00%)
3 (3.00%) high mild
3 (3.00%) high severe