-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache get_decoder_class #1833
Comments
Because the decoding is being done by a third-party library (scalecodec), we will have to monkey-patch in a import functools
from scalecodec import base as scalecodec_base
import bittensor as bt
original_get_decoder_class = scalecodec_base.RuntimeConfiguration.get_decoder_class
@functools.cache
def patched_get_decoder_class(self, type_string):
return original_get_decoder_class(self, type_string)
scalecodec_base.RuntimeConfiguration.get_decoder_class = patched_get_decoder_class
sub = bt.subtensor("finney")
sub.get_delegates() With this, we can see a reduction of calls (for In real-world performance, we see that the entire execution time for this script improves by ~48% with the patch implemented. Note that this only involves running five times each, so results may vary with times of day, ping, etc.:
I believe implementing this in the code base will drastically reduce overall decode time. |
@RomanCh-OT had some concerns about potential memory leak caused by caching, so I investigated. Given the way the |
Opened polkascan/py-scale-codec#117 to add the caching ability and functionality to the scalecodec library. |
Currently, a large portion of time (29000+ calls for get_delegates) for RPC calls is taken up by decoding. Profiling this shows that the vast majority of this decoding time is actually caused by calls to the
scalecodec.base.RuntimeConfiguration.get_decoder_class
method.Because of the fairly limited number of decoder classes, we should be able to cache this with
functools.cache
to see large speed improvements.The text was updated successfully, but these errors were encountered: