Skip to content

Re-use the backend instance rather than creating many - #202

Open
TheDistributor wants to merge 1 commit into
masterfrom
mgallwey/cache-backend
Open

Re-use the backend instance rather than creating many#202
TheDistributor wants to merge 1 commit into
masterfrom
mgallwey/cache-backend

Conversation

@TheDistributor

Copy link
Copy Markdown
Contributor

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.

Comment thread pynuodb/crypt.py
# 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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants