-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Buffers: Prevent bug-prone iteration, speed up accidentally-quadratic iteration #369
Buffers: Prevent bug-prone iteration, speed up accidentally-quadratic iteration #369
Conversation
Where did you encounter those nested buffers? The |
Nested buffers occur internally, so this affects the running time even if the user's code doesn't have direct access to them. Checking for errors makes even more sense in this case. The user shouldn't be able to trigger this issue even if they wanted to, and the checks make sure that no data is lost internally (e.g. by new code). I personally encountered these because |
There are two issues here which we should not mix up:
In any case these changes are orthogonal to all the other work you are doing, right? |
|
d34cbe2
to
a9a3446
Compare
Changes since last push:
|
a9a3446
to
6ce5366
Compare
get_last_nested() used to walk the entire list, requiring linear time. Because get_last_nested() is also invoked a linear amount of times, this leads to an overall quadratic running time in order to access all nested buffers. This effect is called 'accidentally quadratic', and is a common issue. The 'Can quickly handle deeply nested buffer' test makes sure that this issue does not regress in the future, and also allows me to make some guesstimates about the performance gain: For a nesting depth of 30000, the test is sped up from 4 seconds to less than 0.01 seconds. Here are some more practical numbers: Iterating over the entire planet (which has very large blocks and thus deeply nested buffers), I observe a speed up from 163.1 s to 160.9 s according to hyperfine (10 runs each).
6ce5366
to
4a12e27
Compare
Changes since last push summary:
|
CI failure seems to be a flake: It fails long before the code of this PR becomes relevant, specifically during package installation. |
Closing because you don't seem to accept any PRs at this time. |
This PR:
Buffer::get_last_nested()
. This method used to be accidentally-quadratic: Each invocation takes a linear amount of time in the depth, and needs to be invoked a linear amount of times in order to iterate all buffers. This means an overall quadratic running time, even though one would expect a linear running time. I also added a test that is very sensitive to this (4s versus <0.01s). When iterating over the entire planet, I observe a speedup from 163.183 s to 160.942 s. (And an observed stddev of 0.836 s, so this result has 2.68 sigma. Physics scientists would laugh at that, but it's good enough proof for me, in this case.)