[php-src] PR #21726: ext/uri: speed up Uri\Rfc3986\Uri component reads (~22%)

From: Date: Sat, 11 Apr 2026 19:59:32 +0000
Subject: [php-src] PR #21726: ext/uri: speed up Uri\Rfc3986\Uri component reads (~22%)
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35678@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21726 Author: iliaal ## Summary Speed up Uri\Rfc3986\Uri parse + component reads by ~22% on a realistic URL mix. Five targeted changes in ext/uri/uri_parser_rfc3986.c; the full per-change breakdown is in the commit message. ## Benchmark 17 URL shapes: plain http/https, deep paths, with query/fragment, with userinfo, IPv4, IPv6, mailto, URN, data, file, relative. 100K iterations per run, 1.7M parses per benchmark, CPU pinned via taskset -c 0, same-session A/B (stash + rebuild + rerun each direction). | | baseline | optimized | delta | |--|--|--|--| | Uri\Rfc3986\Uri::parse only | 0.394s (4.30M/s) | 0.378s (4.50M/s) | −4% | | Uri\Rfc3986\Uri::parse + 7 reads | **0.842s (2.02M/s)** | **0.653s (2.60M/s)** | **−22% / +29% throughput** | | Uri\WhatWg\Url::parse only | 0.410s (4.15M/s) | 0.408s (4.16M/s) | noise | | Uri\WhatWg\Url::parse + 8 reads | 0.599s (2.84M/s) | 0.592s (2.89M/s) | noise | The WhatWG rows are a control. This patch only touches the RFC3986 backend, so WhatWG throughput should stay within noise, and it does. ## What's in the patch 1. get_normalized_uri() aliases the raw URI when uriNormalizeSyntaxMaskRequiredExA reports a zero dirty mask, skipping the full uriCopyUriMmA + uriNormalizeSyntaxExMmA pass for the common case where the parsed URI is already canonical. The mask is cached so repeated non-raw reads on one instance scan once. Biggest single contributor. 2. Port cache on the uris struct. Parse-time validation stashes the converted zend_long; the first port_read serves from cache; writes invalidate. 3. port_str_to_zend_long_checked swaps stack-copy + ZEND_STRTOUL for an inline digit accumulator. Uriparser has already validated the text as ASCII digits only, so strtoul's parse-flags, sign handling, base detection, and stop-char scanning are dead weight. 4. uriparser_create_uris uses emalloc + targeted field init instead of ecalloc, avoiding ~440 bytes of zeroing per parse. 5. php_uri_parser_rfc3986_destroy skips uriFreeUriMembersMmA(&normalized_uri, ...) when it was never built or when it aliases the raw uri. Required by the emalloc change since the struct is no longer fully zeroed.

« previous php.git-pulls (#35678) next »