Lazy-load some submodules inside ncclient.transport only when needed #638
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 is aim to reduce some unnecessary memory usage during the import of
ncclient.transport
by lazy-loading some submodules only when they are needed.In file
ncclient/transport/__init__.py
, the following submodules are imported by default:These package cause a ton of unnecessary memory usage when
ncclient.transport
is imported, especially when the user does not use these transport methods.For example, I only use
UnixSocketSession
in my scenario, but when I importncclient.transport
, it also importsSSHSession
andTLSSession
, which I never use. This is a waste of memory.Here is the memory usage before the change:
After the change, the memory usage is reduced significantly:
Since this is my first PR to the
ncclient
project, I would like to ask for your review and feedback on this change. Any suggestions or improvements are welcome.