Commit b5d6508
committed
ext/uri: speed up Uri\Rfc3986\Uri component reads
Five related changes to uri_parser_rfc3986.c that together cut parse
+ 7 reads on a 17-URL mix from 0.842s to 0.653s (1.7M parses, pinned
to a single CPU). That's a 22% wall-time reduction and a 29% throughput
increase. Parse-only moves from 0.394s to 0.378s, about 4%.
1. get_normalized_uri() now aliases the raw URI when nothing requires
normalization. uriNormalizeSyntaxMaskRequiredExA reports which
components need rewriting; a zero mask means the parsed URI is
already canonical and the code skips the uriCopyUriMmA deep copy
plus the full uriNormalizeSyntaxExMmA pass. This is the biggest
single contributor. The dirty mask is cached on the struct so
multiple non-raw reads on the same instance run the scan once.
2. The port now lives in a cache on the uris struct. The parse path
stashes the converted zend_long directly, so the first port_read
serves it without re-scanning. Subsequent reads short-circuit. The
write path invalidates the cache.
3. port_str_to_zend_long_checked replaces its stack-copy + ZEND_STRTOUL
with an inline digit accumulator. Uriparser has already validated
that the port text is ASCII digits only, so the branch-heavy strtoul
path is unnecessary.
4. uriparser_create_uris uses emalloc + targeted field init instead of
ecalloc. The struct is ~440 bytes. We overwrite the uri member right
after this function returns and we only touch normalized_uri once
the init flag becomes true, so only the flag fields and dirty_mask
need zeroing.
5. php_uri_parser_rfc3986_destroy skips uriFreeUriMembersMmA on
normalized_uri when it was never built or when it aliases the raw
uri. Paired with the emalloc change: the struct used to be fully
zeroed by ecalloc, so the free was safe without a guard. Now that
most of the struct is uninitialized, the guard is required.
No behavior change. All 309 tests in ext/uri/tests pass. I also checked
that URIs which need normalization (http://EXAMPLE.com/A/%2e%2e/c
resolving to /c) still hit the full normalize path, so the alias
shortcut is gated by a non-zero dirty mask.1 parent 8ad79e1 commit b5d6508
1 file changed
+69
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
| |||
85 | 90 | | |
86 | 91 | | |
87 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
88 | 107 | | |
89 | | - | |
| 108 | + | |
90 | 109 | | |
91 | 110 | | |
92 | 111 | | |
93 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
94 | 117 | | |
95 | 118 | | |
96 | 119 | | |
| |||
285 | 308 | | |
286 | 309 | | |
287 | 310 | | |
288 | | - | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
289 | 314 | | |
290 | 315 | | |
291 | 316 | | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
296 | 323 | | |
297 | 324 | | |
298 | 325 | | |
| |||
303 | 330 | | |
304 | 331 | | |
305 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
306 | 344 | | |
307 | 345 | | |
308 | 346 | | |
309 | | - | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
310 | 351 | | |
| 352 | + | |
| 353 | + | |
311 | 354 | | |
312 | 355 | | |
313 | 356 | | |
| |||
316 | 359 | | |
317 | 360 | | |
318 | 361 | | |
| 362 | + | |
319 | 363 | | |
320 | 364 | | |
321 | 365 | | |
| 366 | + | |
| 367 | + | |
322 | 368 | | |
323 | 369 | | |
324 | 370 | | |
| |||
487 | 533 | | |
488 | 534 | | |
489 | 535 | | |
490 | | - | |
| 536 | + | |
491 | 537 | | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
492 | 541 | | |
493 | 542 | | |
494 | 543 | | |
| |||
545 | 594 | | |
546 | 595 | | |
547 | 596 | | |
| 597 | + | |
| 598 | + | |
548 | 599 | | |
549 | | - | |
| 600 | + | |
| 601 | + | |
550 | 602 | | |
551 | 603 | | |
552 | 604 | | |
553 | 605 | | |
554 | 606 | | |
555 | 607 | | |
| 608 | + | |
556 | 609 | | |
557 | 610 | | |
558 | 611 | | |
559 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
560 | 617 | | |
561 | 618 | | |
562 | 619 | | |
| |||
626 | 683 | | |
627 | 684 | | |
628 | 685 | | |
629 | | - | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
630 | 689 | | |
631 | 690 | | |
632 | 691 | | |
| |||
0 commit comments