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
s3.cn-north-1.amazonaws.com.cn and com.cn are valid.
but the intermediates cn-north-1.amazonaws.com.cn and amazonaws.com.cn are not valid.
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, where parts.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.
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