Cache socket port number in bolt class #724
Merged
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.
The port number is (at least) queried for each debug log line. No matter if logging is enabled or not. Wrapping
socket.getsockname()
into a check whether debug logging is enabled or not, to only query it when necessary, made the driver slower for environments with a fast response (read: my local machine). Therefore, caching the port number is the only viable compromise. The downside is that this assumes that the port number never changes. As the driver is right now, it hands over all control over the socket to the Bolt class, so this assumption is safe. But it introduces complexity in the code base by adding the need to know about and adhere to this principle in future changes.Background: a customer complained about the calls slowing down their deployment significantly. On my local machine it's actually really fast and commenting out the line in question (
neo4j-python-driver/neo4j/_async/io/_bolt5.py
Line 271 in 1ed96f9