⚡️ Speed up method NoOpControlAuthnPlugin.get_login_details by 281%
#36
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.
📄 281% (2.81x) speedup for
NoOpControlAuthnPlugin.get_login_detailsinframework/py/flwr/superlink/auth_plugin/noop_auth_plugin.py⏱️ Runtime :
1.69 milliseconds→444 microseconds(best of140runs)📝 Explanation and details
The optimization replaces repeated object construction with a pre-computed module-level constant. The original code creates a new
AccountAuthLoginDetailsobject every timeget_login_details()is called, requiring constructor execution and memory allocation. The optimized version creates this object once at module import time as_NOOP_LOGIN_DETAILSand simply returns the same immutable object reference on each call.Key changes:
_NOOP_LOGIN_DETAILScontaining the pre-constructed objectget_login_details()to return the constant instead of creating new instancesWhy this is faster:
The line profiler shows the original constructor call takes 8.2ms total time across multiple invocations, with significant overhead in object instantiation and field assignment. The optimized version reduces this to just 0.6ms - simply returning a reference to an existing object.
Performance characteristics:
This optimization provides consistent 2.8x speedup regardless of call frequency, making it particularly effective for:
get_login_details()is called repeatedlyThe optimization is safe because
AccountAuthLoginDetailsappears to be an immutable data structure (NamedTuple), so sharing the same instance across calls maintains correctness while eliminating redundant object creation overhead.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
To edit these changes
git checkout codeflash/optimize-NoOpControlAuthnPlugin.get_login_details-mha06rmtand push.