Repository navigation
Geodata: skip regexes whose match cannot end like the input - #6868
Closed
4RH1T3CT0R7 wants to merge 1 commit into
Closed
4RH1T3CT0R7 wants to merge 1 commit into
4RH1T3CT0R7 wants to merge 1 commit into
Conversation
most geosite regexes end with a fixed tail such as \.com$, so the pattern is walked back from the end to record the bytes a match can have at each of its last 8 positions, plus one set for every earlier byte when it also starts with ^. Match checks these sets before the literal prefilter and the regexp only nested repeats can blow the walk up, so their steps are capped at 100000 and the guard is dropped past that. 161 of the 163 distinct Loyalsoldier regexes get a guard. it rejects only inputs that cannot match; case folding, non-ASCII, invalid UTF-8 and branches without $ are handled conservatively
Member
|
请尽量把此类pr放在一起 理论上应该和 #6818 在一起的。。 |
Contributor
Author
|
ok, moved it into #6867 together with the rest of the geodata changes |
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.
on real traffic lookups mostly wait on regexes: GEOLOCATION-!CN's 151 regexes take about 95% of a 2-3 µs miss, and PRIVATE's literal-free
^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$costs 300-400 ns on every lookup that reaches it, since #6818 cannot skip itmost of them end with a fixed tail like
\.com$, so at build time each pattern is walked back from the end and the bytes a match can have in its last 8 positions are recorded. Match checks the input against those sets first and runs the regexp only when they allow a match. the guard is conservative (case folding, non-ASCII, (?m), branches without $), only nested repeats can drop it, and 161 of the 163 Loyalsoldier regexes get onelookups reaching PRIVATE get about 80% faster, regex-bound misses and Match on dns2/all3 about 40%, and hits are unchanged
lookups, paired A/B, median ns/op
Loyalsoldier geosite.dat, Ryzen 9 5900X, go1.27.0, GOMAXPROCS=4. main vs main gives about ±2.5% on hit rows
soundness