Add default_symcrypt_provider_arc for cached provider access#24
Merged
Merged
Conversation
default_symcrypt_provider() reallocates the cipher_suites and kx_groups Vecs on every call. Callers that need an Arc<CryptoProvider> (the shape ClientConfig::builder_with_provider expects) end up paying that cost on every connection / test / config build. Add default_symcrypt_provider_arc() returning a process-cached Arc<CryptoProvider> via std::sync::OnceLock. First call constructs once; subsequent calls are an Arc::clone. Bumps MSRV 1.64.0 -> 1.70.0 (required by OnceLock) and crate version 0.2.2 -> 0.2.3.
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
default_symcrypt_provider_arc() -> Arc<CryptoProvider>returning a process-cached provider viastd::sync::OnceLock. First call constructs once; subsequent calls are an atomic refcount bump.OnceLock).Motivation
default_symcrypt_provider()allocates a freshVec<SupportedCipherSuite>andVec<&dyn SupportedKxGroup>on every call. Code paths that need anArc<CryptoProvider>(the shape rustls'ClientConfig::builder_with_provideraccepts) end up writingArc::new(default_symcrypt_provider())and re-paying that cost per connection / per test / per config builder.default_symcrypt_provider_arc()gives callers a zero-allocation hot path while leavingdefault_symcrypt_provider()untouched for callers that genuinely want a fresh, owned provider.API
MSRV note
OnceLockis stable since 1.70.0. If keeping 1.64.0 is a hard requirement, the alternative isonce_cell::sync::OnceCell(already a dev-dependency); happy to switch if preferred.Test plan
test_default_symcrypt_provider_arc_is_cachedassertsArc::ptr_eqacross two calls and that the cached provider has the expected cipher suites / kx groups.cargo clippy --lib -- -Dwarningsclean.cargo test— existing tests unaffected.