Skip to content

Commit

Permalink
LibURL: Avoid expensive IDNA::to_ascii() for all-ASCII domain strings
Browse files Browse the repository at this point in the history
20% of CPU usage when loading https://utah.edu/ was spent doing these
ASCII conversions in URL parsing.
  • Loading branch information
awesomekling committed Apr 5, 2024
1 parent 93ba99f commit 0240262
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Userland/Libraries/LibURL/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,15 @@ static ErrorOr<String> domain_to_ascii(StringView domain, bool be_strict)
{
// 1. Let result be the result of running Unicode ToASCII with domain_name set to domain, UseSTD3ASCIIRules set to beStrict, CheckHyphens set to false, CheckBidi set to true, CheckJoiners set to true, Transitional_Processing set to false, and VerifyDnsLength set to beStrict. [UTS46]
// 2. If result is a failure value, domain-to-ASCII validation error, return failure.

// OPTIMIZATION: Fast path for all-ASCII domain strings.
if (all_of(domain, is_ascii)) {
// 3. If result is the empty string, domain-to-ASCII validation error, return failure.
if (domain.is_empty())
return Error::from_string_literal("Empty domain");
return String::from_utf8_without_validation(domain.bytes());
}

Unicode::IDNA::ToAsciiOptions const options {
Unicode::IDNA::CheckHyphens::No,
Unicode::IDNA::CheckBidi::Yes,
Expand Down

0 comments on commit 0240262

Please sign in to comment.