Improve performance and consistency of alias lookups #611
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current alias lookup implementation adds a separate entry to the lookup map for each IP address in the network of the alias. That's a lot of map entries for, say, a
/16
network. This map becomes even larger ifadd_captid_to_resolve
is enabled. This patch replaces this with a treap-based lookup.The improvement in performance depends on how many aliases you have and how large your networks are. For our setup with ~80 aliases and a fair number of
/19
and/22
networks, the speedup amounts to about 3x.Alias lookups are now also more consistent. For aliases with partially overlapping networks, the alias with the longest prefix match wins, not the one that happens to be the last one to be added to the lookup map.
The new
cidrtree
dependency bumps the minimum Go version to 1.21.Looks like it has been a while since the code base was formatted with gofmt, so this patch unfortunately also includes some formatting changes for the changed files.