-
Notifications
You must be signed in to change notification settings - Fork 127
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
reader: optimize BackoffTimer using float #156
Conversation
I still think this is silly, the culprit is clearly (at least) this line https://github.com/nsqio/pynsq/blob/master/nsq/reader.py#L358, if that performs no decimal calculations how much does that buy us? FWIW this PR might be solving exactly that, since it caches the value, but do we need all the other noise? |
I think using It just happens that the numbers used for short_length and long_length have both 2 and 5 as prime factors instead of just 2, so base 10 avoids a rounding errors in short_unit and long_unit that compound, that cause you to be an iota off from 0 after a test does the same number of I'll run the simple benchmark with just the |
I don't disagree about decimal/float, but we should first make sure it's called only when necessary and then optimize it if necessary. This code is ancient Bitly code pre-dating pynsq. |
b02ada4
to
d739920
Compare
Putting everything back, and then caching just I also think it's weird that the test uses min_interval=0.1, but actual pynsq reader always uses min_interval=0, and that's actually a significant number to a branch in the reader code. So if I were to do the "big cleanup" option for this code ... I would also get rid of min_interval :) |
let me know if/when to squash |
🔨 |
cache the calculation+conversion for get_interval() if get_interval() is 0, then success() can be short-circuited
d739920
to
f632b56
Compare
I'll run this locally later today and see how it shows up in the profiling output. |
thanks! |
my version of #155
performance tested with @virtuald's rawperf.py on a plugged-in 2013 macbook pro retina 13"
Maybe a refactor - to not call these methods so much - is what the library really needs, but this was a fun easy exercise 😁