⚡️ Speed up method KeepKeyPlugin.get_client by 13%
#137
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.
📄 13% (0.13x) speedup for
KeepKeyPlugin.get_clientinelectrum/plugins/keepkey/keepkey.py⏱️ Runtime :
21.6 milliseconds→19.2 milliseconds(best of35runs)📝 Explanation and details
The optimization achieves a 12% speedup by eliminating redundant method calls through device manager caching.
Key optimization:
self.device_manager()on everyget_client()invocation, which involved a method call overhead. The optimized version cachesself.parent.device_managerasself._device_managerduring initialization and accesses it directly.Performance impact:
devmgr = self.device_manager()line dropped from 893,101ns to 374,238ns per hit (58% faster)get_client()appears to be called frequently in hardware wallet operationsWhy this works:
Test case benefits:
The optimization maintains full backward compatibility while providing measurable performance gains in hardware wallet intensive operations.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-KeepKeyPlugin.get_client-mhxieuk2and push.