Repository navigation
Resolve EQUALITY keys via hash lookup during search - #12
Open
anantsahrawat wants to merge 2 commits into
Open
anantsahrawat wants to merge 2 commits into
anantsahrawat wants to merge 2 commits into
Conversation
added 2 commits
November 2, 2026 10:43
Search used to evaluate every key of the inverted index against the request to find matching keys, so its cost grew with the number of distinct keys even when few criteria matched. EQUALITY keys with string, boolean or standard numeric values are now bucketed by (path, preOperations) and normalised value, and resolved with a hash lookup; all other keys are still evaluated one by one. Value normalisation mirrors Utils.compare, so results are unchanged. The lookup is derived lazily from each posting-list map and rebuilt when the indexers replace the map. It is not serialised. The behaviour can be turned off with MustangEngine.builder().equalityKeyLookupEnabled(false). Adds parity tests against the previous scan behaviour and an equality-heavy JMH benchmark, and parameterises the existing benchmarks over the flag.
anantsahrawat
force-pushed
the
feature/equality-key-hash-lookup
branch
from
November 2, 2026 05:13
d37aa0a to
8035d99
Compare
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Problem
To find the keys that a request satisfies,
DNFMatcherandCNFMatcherevaluate every key in the inverted index (map.keySet().stream().filter(CaveatEnforcer...)). Search cost therefore grows with the number of distinct keys in the index, even when only a few criteria match. Indexes with many distinct EQUALITY values are hit hardest: one id per criteria (e.g. geo-fence ids) or large value lists (e.g. allowed plan ids).Change
EqualityKeyLookup(mustang-models) bucketsEQUALITYkeys whose value is a string, boolean or standard number. Buckets are keyed by(path, preOperations)first, then by normalised value. All other keys (other caveats, or other value types) stay in a scan list.MatchingKeyResolver(mustang-core), used by both matchers:The merge, scoring and tautology handling are unchanged.
Normalisation mirrors
Utils.compare:doubleValue()(-0.0folded,NaNnever matches);The lookup is derived from each posting-list map and cached in
InvertedIndex(@JsonIgnore, excluded from equals/hashCode/toString). The indexers always install a new map instance, so the cache is rebuilt lazily when the map changes. No changes were needed in add/update/delete/replace/import, and snapshot/export output is unchanged.Enabled by default. It can be turned off with
MustangEngine.builder().equalityKeyLookupEnabled(false).SearchFacadekeeps its existing 4-argumentsearchoverload.Compatibility
MustangEnginehas one new builder field, so its all-args constructor signature changes. Nothing in the repository calls it directly.Tests
SearchTestcases also runratify(), which cross-checks search against scan.EqualityKeyLookupSearchTest(11 tests) compares lookup-enabled and lookup-disabled engines on the same index. It covers:Benchmarks
Laptop, JDK 21. Indicative numbers.
New
MustangEqualitySearchBenchmark(average time per search, 1 thread,-prof gc):Existing benchmarks (README defaults: throughput,
Threads.MAX, 1 iteration; now parameterised over the flag):The existing benchmarks draw values from
[0, 100)across 26 paths, so they have at most ~2.6K distinct keys and long posting lists. The gains there are smaller (up to ~2.7× for CNF). Merging dominates for large DNF indexes.Run:
Not in scope
Moved from #10 (fork) so CI has access to repository secrets and write permissions.