perf: avoid unnecessary dict allocation in execute_async custom_payload#785
Draft
mykaul wants to merge 1 commit intoscylladb:masterfrom
Draft
perf: avoid unnecessary dict allocation in execute_async custom_payload#785mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul wants to merge 1 commit intoscylladb:masterfrom
Conversation
e8973a0 to
a84f703
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
Session.execute_async()unconditionally allocates an empty dict{}on every call (line 2754):In >99% of calls, neither
custom_payloadnorexecute_asis provided. The empty dict{}is passed toupdate_custom_payload({})which short-circuits immediately because{}is falsy (if other:on protocol.py:94). The dict allocation is pure waste on the hot request path.Summary
custom_payload = custom_payload if custom_payload else {}allocationexecute_asis truthy (the rare DSE proxy-execute case)custom_payloadnow remainsNoneby default;update_custom_payload(None)correctly short-circuits atif other:Testing
tests/unit/test_cluster.pypasscustom_payloadpassed to_create_response_futureisNoneinstead of{}— both are falsy and handled identically byupdate_custom_payload()andencode_message()Benchmarks
Isolated benchmark measuring the allocation pattern (5M iterations):
The common case (no custom payload, no execute_as) sees a 3.19x speedup by eliminating one
dict()allocation per request on the hot path.Pre-review checklist