⚡️ Speed up method DummyClient.get_properties by 254%
#22
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.
📄 254% (2.54x) speedup for
DummyClient.get_propertiesinframework/py/flwr/simulation/ray_transport/ray_client_proxy_test.py⏱️ Runtime :
3.84 milliseconds→1.08 milliseconds(best of383runs)📝 Explanation and details
The optimized code achieves a 254% speedup by eliminating expensive object creation overhead in the hot path.
Key optimizations:
Avoided ConfigRecord constructor overhead: Instead of calling
ConfigRecord({"result": str(result)})which creates a temporary dictionary and goes through the full constructor, the code usesConfigRecord.__new__()and directly assigns to._data, bypassing intermediate allocations.Cached string conversion: The
str(result)call is performed once and stored instr_resultto avoid redundant string conversions.Cached dictionary reference:
config_rec = self.client_state.config_recordsavoids repeated attribute lookups.Performance impact: The line profiler shows the original bottleneck was the ConfigRecord creation (89.2% of runtime, 12.38ms). The optimization reduces this to just 19.4% of total runtime (528μs) - a ~23x improvement on the critical path.
Best use cases: This optimization excels when
get_properties()is called frequently (as shown in the large-scale tests with 1000+ clients), since it eliminates per-call allocation overhead. The optimization maintains identical functionality while dramatically reducing memory churn in high-frequency scenarios.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
🔎 Concolic Coverage Tests and Runtime
To edit these changes
git checkout codeflash/optimize-DummyClient.get_properties-mh16n8b9and push.