perf: replace functools.partial with closure in _query callback#786
Draft
mykaul wants to merge 1 commit intoscylladb:masterfrom
Draft
perf: replace functools.partial with closure in _query callback#786mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul wants to merge 1 commit intoscylladb:masterfrom
Conversation
8809c16 to
9c8f83f
Compare
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.
Motivation
ResponseFuture._query()creates afunctools.partial(self._set_result, host, connection, pool)on every single query (line 4623). This is the primary response callback, executed for every request.partialhas non-trivial allocation overhead: it creates a newpartialC object, allocates a tuple for positional args, and invocation goes throughpartial.__call__indirection.Summary
partial(self._set_result, host, connection, pool)with a closure using default-argument capturepartialobject allocation and__call__indirection__defaults__tuple, making both creation and invocation cheaperBefore
After
Testing
tests/unit/test_cluster.pypasscb(response)callsself._set_result(host, connection, pool, response)identicallypartialuses in cluster.py (connection factory, watchers, reprepare, timeout rescheduling) are left unchanged as they are on cold/rare pathsBenchmarks
Isolated benchmark measuring callback creation + 1 invocation (5M iterations):
functools.partial(before)The default-argument closure was chosen as it has the best total cost (creation + invocation), since both happen exactly once per request.
Pre-review checklist