Optimise select() for long subdomains #268
Open
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.
Current implementation of select() searches for longest matching TLDs from the right end all the way to the left end.
This approach is necessary to handle edge cases like example.s3.cn-north-1.amazonaws.com.cn, where
However, this disadvantages URLs with long subdomains like
a.very.long.subdomain.example.co.uk
.We can terminate the search early by limiting the search size to
[parts.size, @max_rule_size].min
, whereparts.size
is number of parts in the hostname, and@max_rule_size
is the number of parts in the largest rule in@rules
.Also replaced the kernel loop with a faster bounded while loop, as it is possible to convert the current break condition to a loop condition.
Before
After