On Fri, Nov 20, 2026 at 2:27 PM Yann Ylavic <[email protected]> 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.
> 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
>          │
> └────────────────────────┴────────────────┴─────────────┴───────────────────────┘

Sorry, got mangle by gmail.. here again:

┌────────────────────────┬─────────┬────────┬──────────────┐
│         scheme         │ current │ switch │ perfect hash │
├────────────────────────┼─────────┼────────┼──────────────┤
│ http                   │ 15.5    │ 18.8   │ 54.5         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ ftp                    │ 27.9    │ 16.5   │ 52.9         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ https                  │ 36.1    │ 32.9   │ 53.4         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ gopher                 │ 42.0    │ 21.3   │ 56.0         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ ldap                   │ 50.2    │ 14.7   │ 49.7         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ nntp                   │ 61.6    │ 18.2   │ 51.9         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ snews                  │ 67.9    │ 18.6   │ 56.3         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ imap                   │ 79.6    │ 19.0   │ 49.3         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ pop                    │ 81.6    │ 17.3   │ 46.9         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ sip                    │ 95.8    │ 25.8   │ 46.8         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ rtsp                   │ 102.9   │ 20.5   │ 51.3         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ wais                   │ 114.6   │ 19.3   │ 53.1         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ z39.50r                │ 115.6   │ 23.9   │ 67.5         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ z39.50s                │ 124.0   │ 41.2   │ 64.5         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ prospero               │ 134.3   │ 29.8   │ 67.0         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ nfs                    │ 149.9   │ 25.7   │ 46.9         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ tip                    │ 158.2   │ 17.1   │ 46.3         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ acap                   │ 170.0   │ 20.6   │ 51.5         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ telnet                 │ 179.7   │ 33.8   │ 61.4         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ ssh                    │ 181.6   │ 36.0   │ 49.6         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ HTTP                   │ 15.1    │ 18.5   │ 56.4         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ Prospero               │ 138.9   │ 29.7   │ 72.8         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ SSH                    │ 178.4   │ 36.5   │ 47.3         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ unknown                │ 179.2   │ 5.9    │ 65.3         │
├────────────────────────┼─────────┼────────┼──────────────┤
│ mean over all 24 names │ 104.2   │ 23.4   │ 54.9         │
└────────────────────────┴─────────┴────────┴──────────────┘


>
> Works for you?
>
> Regards;
> Yann.

Reply via email to