On 11/20/26 2:27 PM, Yann Ylavic wrote:
> On Thu, Nov 19, 2026 at 2:44 PM Branko Čibej via dev <[email protected]>
> wrote:
>>
>>> On 18. 11. 2026 09:59, Ruediger Pluem via dev wrote:
>>>
>>> On 11/16/26 4:10 PM, Yann Ylavic wrote:
>>>
>>> diff -ru a/uri/apr_uri.c b/uri/apr_uri.c
>>> --- a/uri/apr_uri.c 2026-11-16 16:02:56.759516227 +0100
>>> +++ b/uri/apr_uri.c 2026-11-16 16:02:56.784734796 +0100
>>> @@ -999,6 +999,7 @@
>>> if (have_zone_id) {
>>> percent_decode_scope_zone_id(uptr->hostname);
>>> }
>>> + uptr->port = apr_uri_port_of_scheme(uptr->scheme);
>>> goto deal_with_path;
>>> }
>>> uptr->hostname = apr_pstrmemdup(p,
>>>
>>> Sounds sensible. Maybe AI can help us generate all the test cases such that
>>> we can be sure it works and keeps working after changes.
>
> See attached "apr-uri-default-port.patch" (including tests).
>
>> I have an implementation ready that uses a generated minimal perfect hash
>> function for lookups. The hash function is O(strlen(key)) to calculate the
>> hash of the lookup key and O(1) to find the scheme. Except for the very
>> first scheme in in the list, where linear lookup needs just a single
>> strcasecmp(), it's faster by up to 5 times from the current lookup.
>
> This adds quite some infrastructure to APR (Python generator,
> template, generated .inc, uri_schemes.h, non-static apr__uri_schemes),
> what about something like the attached "apr-uri-port-of-scheme.patch"
> (including tests)?
> It's simpler (IMHO), and in my testing it works faster (probably due
> to the multiplies for the perfect hashing) and also avoids both
> strcasecmp() (current code) and tolower() (your patch) which are
> locale dependent.
Can't we even speed up things more for https by
Instead of
case 'h': case 'H':
if (!apr_cstr_casecmp(scheme_str, "http"))
return APR_URI_HTTP_DEFAULT_PORT;
if (!apr_cstr_casecmp(scheme_str, "https"))
return APR_URI_HTTPS_DEFAULT_PORT;
break;
using
case 'h': case 'H':
if (!apr_cstr_casecmpn(scheme_str, "http", 4))
switch (scheme_str[4]) {
case '\0':
return APR_URI_HTTP_DEFAULT_PORT;
case 's': case: 'S':
return APR_URI_HTTPS_DEFAULT_PORT;
}
break;
Regards
Rüdiger
> Here are my numbers (ns per call, clock of 1.2 GHz, median over 5
> interleaved rounds):
>
> ┌────────────────────────┬────────────────┬─────────────┬───────────────────────┐
> │ scheme │ current linear │ switch │ perfect
> hash │
> ├────────────────────────┼────────────────┼─────────────┼───────────────────────┤
> │ http │ 13.7 │ 17.5 │ 51.8
> │
> ├────────────────────────┼────────────────┼─────────────┼───────────────────────┤
> │ https │ 33.4 │ 31.7 │ 54.3
> │
> ├────────────────────────┼────────────────┼─────────────┼───────────────────────┤
> │ prospero / Prospero │ 138.9 / 130.2 │ 27.8 / 31.3 │ 66.2 / 68.5
> │
> ├────────────────────────┼────────────────┼─────────────┼───────────────────────┤
> │ ssh / SSH │ 176.2 / 180.8 │ 35.8 / 36.8 │ 46.9 / 46.4
> │
> ├────────────────────────┼────────────────┼─────────────┼───────────────────────┤
> │ unknown │ 171.7 │ 5.8 │ 66.3
> │
> ├────────────────────────┼────────────────┼─────────────┼───────────────────────┤
> │ mean over all 24 names │ 100.8 │ 22.9 │ 53.5
> │
> └────────────────────────┴────────────────┴─────────────┴───────────────────────┘
>
> Works for you?
>
> Regards;
> Yann.
>