-
Notifications
You must be signed in to change notification settings - Fork 907
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
Rework NetmaskTree for better CPU and memory efficiency. #8355
Conversation
oh, seems like I didn't actually compile the recursor. need to fix a few things. |
dc73b7b
to
7e133b3
Compare
This pull request introduces 1 alert when merging 7e133b3 into ef9ed3b - view on LGTM.com new alerts:
|
For some reason, GitHub doesn't list the commits in the proper sequence. Not practical for review. Proper order from last to first commit:
|
Fixing the LGTM alert. |
37eb1fc
to
017bf46
Compare
OK, worked around the GitHub commit order bug by rebasing and rewording every commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, a few comments but nothing bad.
A very quick test shows a very nice decrease in memory usage and insertion/lookup time, with a very small increase of the deletion time (even when compared to the existing "cleaning up" case) that probably doesn't matter to us.
I'll do more tests later.
OK, I'll address these soonish. I also have a few other small things I'd like to change still. |
017bf46
to
aafc112
Compare
I addressed most comments and changed a few things:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just a nit but amending the commits makes it hard for me to spot what actually changed since my initial review :-)
Yeah, that is a bit easier in GitLab it seems... |
This branch has conflicts that must be resolved |
Loving this PR and would even love it more if it got finished :-) @stephanbosch do you think you'll have some time to spend to make it ready for merge? |
aafc112
to
f88ae26
Compare
Rebased and CI seems to like it still. |
f88ae26
to
688c528
Compare
…for for IPv4 and IPv6 This simplifies the code considerably.
Makes using `continue' easier in later commit.
Later commit relies on this.
Before, it created a tree node for every network bit in the netmask. Now, it only creates a tree node when necessary (only for values and branches).
This makes address bits below the network mask all zero, which is consistent with the tree's behavior. This change addresses one sensitivity to this behavioral change in the recursor cache.
Potentially leaving branches full of unassigned nodes unnecessarily complicates tree algorithms. Disabling tree cleanup was not used anywhere, except for a unit test. Note that, after this change, individual branch nodes can still be unassigned, but not the whole branch. So, when e.g. the left sub-branch of a node exists, algorithms can rely on the fact that there is at least one assigned node in there.
Before, it used the internal std::set.
Needed to provide a begin() iterator in constant time.
688c528
to
3a086a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, many thanks! Just one nit but we can fix it later.
It is now superfluous.
…an a pointer. It no longer needs to be allocated separately.
…ce rather than a pointer. This is possible now that the iterator type is no longer dictated by the internal std::set. This changes the NetmaskTree::iterator API, but it makes it more standard, less cumbersome, and less confusing.
This prevents changing the key used by the tree, which would otherwise provide an opportunity to corrupt the tree.
3a086a4
to
0c4df7c
Compare
Short description
The existing implementation of class NetmaskTree was inefficient because:
These changes mend both these problems, yielding an overall decrease in CPU usage and memory requirements.
Checklist
I have: