-
Notifications
You must be signed in to change notification settings - Fork 3.8k
perf(catalog): split exact matches & pattern #7340
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
Merged
Mzack9999
merged 4 commits into
projectdiscovery:dev
from
mikhail5555:feature/improved-filter-performance
Apr 29, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
643a64c
split exact matches and pattern matches for increased performance dur…
mikhail5555 ad91d5d
fix comment, add [ to pattern, add thread-safe disclaimed even though…
mikhail5555 ec5f650
remove unnecessary or misleading comments from bench
mikhail5555 86cc092
finalizing
Mzack9999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be removed after review, let me know if you want me to do it. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package index | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
| ) | ||
|
|
||
| const templateCount = 10_000 | ||
|
|
||
| func makeMetadataCorpus(n int) []*Metadata { | ||
| corpus := make([]*Metadata, n) | ||
| for i := range n { | ||
| corpus[i] = &Metadata{ | ||
| ID: fmt.Sprintf("cve-2021-%04d", i), | ||
| Tags: []string{"cve", "http"}, | ||
| Authors: []string{"tester"}, | ||
| Severity: "critical", | ||
| ProtocolType: "http", | ||
| } | ||
| } | ||
| return corpus | ||
| } | ||
|
|
||
| // mixedFilter builds a realistic filter: exactIDs exact IDs (~1/3 match corpus) + wildcardPatterns glob patterns (no match) | ||
| func mixedFilter(exactIDs, wildcardPatterns int) *Filter { | ||
| ids := make([]string, 0, exactIDs+wildcardPatterns) | ||
| for i := range exactIDs { | ||
| ids = append(ids, fmt.Sprintf("cve-202%d-%04d", i%3, i)) // ~1/3 hit corpus (year 2021) | ||
| } | ||
| for i := range wildcardPatterns { | ||
| ids = append(ids, fmt.Sprintf("sqli-%04d-*", i)) // wildcard, no match | ||
| } | ||
| return &Filter{IDs: ids} | ||
| } | ||
|
|
||
| func BenchmarkFilterMatches(b *testing.B) { | ||
| corpus := makeMetadataCorpus(templateCount) | ||
|
|
||
| cases := []struct{ exact, wildcards int }{ | ||
| {10, 0}, | ||
| {100, 0}, | ||
| {1000, 0}, | ||
| {100, 1}, | ||
| {100, 3}, | ||
| {100, 5}, | ||
| } | ||
|
|
||
| for _, tc := range cases { | ||
| b.Run(fmt.Sprintf("ids=%d,patterns=%d", tc.exact, tc.wildcards), func(b *testing.B) { | ||
| b.ReportAllocs() | ||
|
|
||
| filter := mixedFilter(tc.exact, tc.wildcards) | ||
| filter.Compile() | ||
| for b.Loop() { | ||
| for _, meta := range corpus { | ||
| _ = filter.matchesIncludeID(meta.ID) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.