Skip to content

Replace linear IP blocklist scan with indexed trie lookup#322

Open
Mishenevd wants to merge 1 commit into
mainfrom
fix/iplist-blocklist-scan-perf
Open

Replace linear IP blocklist scan with indexed trie lookup#322
Mishenevd wants to merge 1 commit into
mainfrom
fix/iplist-blocklist-scan-perf

Conversation

@Mishenevd

@Mishenevd Mishenevd commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

IPList.containsAddress() scanned every stored subnet/host linearly (O(n)).

At 300k+ entries this costs ~13.7ms per lookup;

isIpBlocked runs it up to 4x per request.

Switched to inet.ipaddr's built-in DualIPv4v6Tries, giving O(bits) containment lookups (~1.2us at the same scale):

A compact binary trie (aka compact binary prefix tree, or binary radix trie)... entry length is capped at 128 bits for IPv6 and 32 bits for IPv4. That makes lookup a constant time operation... construction is O(n), in linear proportion to the number of added elements.

Public API and matches() semantics unchanged; all existing IPListTest cases pass unmodified.

Summary by Aikido

Security Issues: 0 Quality Issues: 0 Resolved Issues: 0

⚡ Enhancements

  • Replaced linear IP set with DualIPv4v6Tries for faster lookups

🔧 Refactors

  • Refactored containsAddress to use trie elementContains call and preserved semantics

More info

IPList.containsAddress() scanned every stored subnet/host linearly
(O(n)). At 300k+ entries this costs ~13.7ms per lookup; isIpBlocked
runs it up to 4x per request. Switched to inet.ipaddr's built-in
DualIPv4v6Tries, giving O(bits) containment lookups (~1.2us at the
same scale). Public API and matches() semantics unchanged; all
existing IPListTest cases pass unmodified.
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../java/dev/aikido/agent_api/helpers/net/IPList.java 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants