perf: speed up URL parsing and IDNA ToASCII - #1142
Open
geeknoid wants to merge 1 commit into
Open
Conversation
Avoid redundant work on the URL parsing hot path: - host: only percent-decode when the input contains a `%`, and append domain hosts to the serialization with `push_str` instead of `write!`. - parser: skip the userinfo scan when the authority has no `@`, and advance the input iterator by the known byte length after scanning a host rather than re-iterating it character by character. - idna: pass ASCII labels with a leading digit through the fast path when the domain cannot be a bidi domain name. Add Callgrind (gungraun) instruction-count benchmarks alongside the existing wall-clock ones. | benchmark | instr orig | instr new | Δ% | ns orig | ns new | ns Δ% | |-----------------|-----------:|----------:|--------:|---------:|---------:|--------:| | plain | 2403 | 1823 | -24.1% | 209 | 168 | -19.6% | | short | 2653 | 2074 | -21.8% | 243 | 186 | -23.5% | | long | 3517 | 2935 | -16.5% | 306 | 253 | -17.3% | | fragment | 3887 | 3306 | -14.9% | 344 | 285 | -17.2% | | port | 2965 | 2318 | -21.8% | 321 | 264 | -17.8% | | hyphen | 3573 | 2607 | -27.0% | 307 | 235 | -23.5% | | leading_digit | 3674 | 2315 | -37.0% | 315 | 211 | -33.0% | | unicode_mixed | 6791 | 6128 | -9.8% | 729 | 678 | -7.0% | | punycode_mixed | 6105 | 5289 | -13.4% | 607 | 498 | -18.0% | | unicode_ltr | 8379 | 7609 | -9.2% | 847 | 788 | -7.0% | | punycode_ltr | 8265 | 7249 | -12.3% | 793 | 692 | -12.7% | | unicode_rtl | 8547 | 7853 | -8.1% | 834 | 766 | -8.2% | | punycode_rtl | 8336 | 7306 | -12.4% | 780 | 660 | -15.4% | | url_to_file_path| 2736 | 2734 | -0.1% | 285 | 280 | -1.8% |
Collaborator
|
Thanks. The IDNA change here may become moot with the redesign required by #1135. |
Author
|
@hsivonen Can we go ahead and merge this PR, it's no-regrets improvement across the board. If some of it is thrown out due to a change in the future, that won't be a problem, right? |
Collaborator
|
I'm OK with landing the |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1142 +/- ##
=======================================
Coverage ? 86.94%
=======================================
Files ? 26
Lines ? 5315
Branches ? 0
=======================================
Hits ? 4621
Misses ? 694
Partials ? 0 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Manishearth
approved these changes
Aug 10, 2026
| bencher = "0.1" | ||
| tester = "0.9" | ||
| serde_json = "1.0" | ||
| gungraun = "0.19.4" |
Member
There was a problem hiding this comment.
Not overly happy about adding another benchmarking framework but it's fine.
Member
|
CI fails |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Avoid redundant work on the URL parsing hot path:
%, and append domain hosts to the serialization withpush_strinstead ofwrite!.@, and advance the input iterator by the known byte length after scanning a host rather than re-iterating it character by character.Add Callgrind (gungraun) instruction-count benchmarks alongside the existing wall-clock ones.