-
Notifications
You must be signed in to change notification settings - Fork 62
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
there should be tests for ReceiveBuffer's big-O behavior #16
Comments
@njsmith not too familiar with the codebase but this seems reasonable. You might want to explore the JIT disabling flags for PyPy though (if you're testing against it) in order to prevent any well intentioned surprises. Also, any chance of just writing your own update:
should do the trick. |
We do test against PyPy, yes. I'm not quite sure how the JIT would cause a problem here, and I'd be nervous about testing a configuration we don't run on, since this would be a safety check, but it makes sense to watch out for it.
|
@njsmith I was assuming that in order to do timing tests you'd run the function repeatedly and compare the total running times. But if you're suggesting to only run the function once the JIT would probably not have a large impact if it didn't already compile the code due to repeated calls from the previous tests. My worry is that in the middle of running the code repeatedly, say 1000 times for N=k, when the tests start for N=100*k the JIT kicks in and optimises the method, which may produce much faster code and thereby hiding the big-O behaviour. |
Ahh, I see, right, that would be a big concern! I was imagining that we'd pick |
It's security-critical that ReceiveBuffer's methods have linear worst-case complexity, and the code we use to accomplish this is non-trivial. There should be tests that we have successfully avoided the O(n^2) trap.
Automated tests for speed are difficult, but I think it's not so bad in this case, because quadratic behavior is so dramatic. So like we could do a worst case test (e.g. repeatedly read 1 byte from an N byte buffer) with N = k and N = 100*k. If we got it right then the latter will be 100x slower; if we got it wrong it'll be 10,000x slower. So we can check that it's less than 1,000x slower, and that gives us a large safety margin on both sides.
Edit:
_obsolete_line_fold
in_readers.py
is another place where it'd be very easy to be accidentally quadratic.The text was updated successfully, but these errors were encountered: