Merge pull request #3628 from yandex/first-significant-subdomain-performance

Attempt to fight back performance of firstSignificantSubdomain function
This commit is contained in:
alexey-milovidov 2018-11-21 05:39:56 +03:00 committed by GitHub
commit 2e15e52b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -202,18 +202,28 @@ struct ExtractFirstSignificantSubdomain
if (!last_3_periods[2]) if (!last_3_periods[2])
last_3_periods[2] = begin - 1; last_3_periods[2] = begin - 1;
if (!strncmp(last_3_periods[1] + 1, "com.", 4) /// Note that in ColumnString every value has zero byte after it. size_t size_of_second_subdomain_plus_period = last_3_periods[0] - last_3_periods[1];
|| !strncmp(last_3_periods[1] + 1, "net.", 4) if (size_of_second_subdomain_plus_period == 4 || size_of_second_subdomain_plus_period == 3)
|| !strncmp(last_3_periods[1] + 1, "org.", 4)
|| !strncmp(last_3_periods[1] + 1, "co.", 3)
|| !strncmp(last_3_periods[1] + 1, "biz.", 4)
|| !strncmp(last_3_periods[1] + 1, "gov.", 4)
|| !strncmp(last_3_periods[1] + 1, "mil.", 4)
|| !strncmp(last_3_periods[1] + 1, "edu.", 4))
{ {
res_data += last_3_periods[2] + 1 - begin; /// We will key by four bytes that are either ".xyz" or ".xy.".
res_size = last_3_periods[1] - last_3_periods[2] - 1; UInt32 key = unalignedLoad<UInt32>(last_3_periods[1]);
return;
/// NOTE: assuming little endian.
/// NOTE: does the compiler generate SIMD code?
/// NOTE: for larger amount of cases we can use a perfect hash table (see 'gperf' as an example).
if ( key == '.' + 'c' * 0x100U + 'o' * 0x10000U + 'm' * 0x1000000U
|| key == '.' + 'n' * 0x100U + 'e' * 0x10000U + 't' * 0x1000000U
|| key == '.' + 'o' * 0x100U + 'r' * 0x10000U + 'g' * 0x1000000U
|| key == '.' + 'b' * 0x100U + 'i' * 0x10000U + 'z' * 0x1000000U
|| key == '.' + 'g' * 0x100U + 'o' * 0x10000U + 'v' * 0x1000000U
|| key == '.' + 'm' * 0x100U + 'i' * 0x10000U + 'l' * 0x1000000U
|| key == '.' + 'e' * 0x100U + 'd' * 0x10000U + 'u' * 0x1000000U
|| key == '.' + 'c' * 0x100U + 'o' * 0x10000U + '.' * 0x1000000U)
{
res_data += last_3_periods[2] + 1 - begin;
res_size = last_3_periods[1] - last_3_periods[2] - 1;
return;
}
} }
res_data += last_3_periods[1] + 1 - begin; res_data += last_3_periods[1] + 1 - begin;