Re-use the backend instance rather than creating many - #202
Open
TheDistributor wants to merge 1 commit into
Open
Re-use the backend instance rather than creating many#202TheDistributor wants to merge 1 commit into
TheDistributor wants to merge 1 commit into
Conversation
adriansuarez
reviewed
Aug 5, 2026
| # state, so sharing one across all Cipher constructions is safe and | ||
| # reduces memory usage/accelerates GC for python programs that use a lot | ||
| # of connections (each connection calls this twice) | ||
| _DEFAULT_BACKEND = default_backend() |
Contributor
There was a problem hiding this comment.
Are all usages of _DEFAULT_BACKEND gated by a check of arc4Imported?
It might be better to have a helper function instead of a variable, and that function will initialize the global default_backend if none is set.
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.
default_backend() is an expensive call that carries no per-use
state, so sharing one across all Cipher constructions is safe and
reduces memory usage/accelerates GC for python programs that use a lot
of connections (each connection calls this twice)
Profiling data showed that when doing benchmarking, the first run was
always faster than subsequent runs. One of the reasons for that was
that GC was spending time cleaning up many instances of the backend.