perf: lazy-init _callbacks/_errbacks in ResponseFuture (25ns saving, 2x speedup, 112 bytes saved)#795
Draft
mykaul wants to merge 1 commit intoscylladb:masterfrom
Draft
perf: lazy-init _callbacks/_errbacks in ResponseFuture (25ns saving, 2x speedup, 112 bytes saved)#795mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul wants to merge 1 commit intoscylladb:masterfrom
Conversation
75550f3 to
40c469e
Compare
Defer list allocation for _callbacks and _errbacks from __init__ to first use in add_callback()/add_errback(). On the synchronous execute path (session.execute()), no callbacks are registered, so both lists are never allocated — saving 112 bytes per request. All access is under _callback_lock; _set_final_result and _set_final_exception use 'or ()' guard to iterate safely when None. Benchmark: 2.2x faster init (0.06 -> 0.03 us), 112 bytes saved/request.
40c469e to
89dabcf
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.
Summary
_callbacksand_errbacksfromResponseFuture.__init__()to first use inadd_callback()/add_errback()session.execute()), no callbacks are registered, so both lists are never allocated — saving 112 bytes per request_callback_lock;_set_final_resultand_set_final_exceptionuseor ()guard to iterate safely whenNoneBenchmark
[]x2Nonex2Memory saved per request (no callbacks): 112 bytes (2 x 56-byte empty list)
Tests