Skip to content

Optimize network address parser#158053

Open
niklasf wants to merge 2 commits into
rust-lang:mainfrom
niklasf:perf/addr-parser
Open

Optimize network address parser#158053
niklasf wants to merge 2 commits into
rust-lang:mainfrom
niklasf:perf/addr-parser

Conversation

@niklasf

@niklasf niklasf commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Motivated by working with datasets of IP addresses.

First commit adds more examples for each case in the benchmark suite.

Second commit splits read_number() into seperate methods for the the max_digits Some(_) and None cases, which by itself significantly helps code generation.

Hoist reading the first digit which is always required.

The path for unlimited digits then no longer has to count digits at all.

Drive-by "fixes" the 10 digit debug assertion (which would be insufficient in base 16). Not actually used anywhere near the limit.

./x bench library/coretests --test-args addr_parser before -> after on AMD Ryzen 9 9950X:

net::addr_parser::bench_parse_ipaddr_v4           81.73ns/iter  +/- 0.60  ->   62.36ns/iter +/- 0.12
net::addr_parser::bench_parse_ipaddr_v6_compress 303.70ns/iter  +/- 1.29  ->  212.80ns/iter +/- 1.25
net::addr_parser::bench_parse_ipaddr_v6_full     453.06ns/iter  +/- 7.89  ->  294.88ns/iter +/- 0.91
net::addr_parser::bench_parse_ipaddr_v6_v4       301.41ns/iter  +/- 1.52  ->  224.82ns/iter +/- 0.99
net::addr_parser::bench_parse_ipv4                87.24ns/iter  +/- 0.32  ->   52.94ns/iter +/- 0.33
net::addr_parser::bench_parse_ipv6_compress      277.92ns/iter  +/- 3.29  ->  195.98ns/iter +/- 1.10
net::addr_parser::bench_parse_ipv6_full          402.48ns/iter +/- 22.20  ->  276.37ns/iter +/- 4.05
net::addr_parser::bench_parse_ipv6_v4            276.78ns/iter  +/- 1.18  ->  216.04ns/iter +/- 1.20
net::addr_parser::bench_parse_socket_v4          105.18ns/iter  +/- 0.79  ->   69.20ns/iter +/- 0.46
net::addr_parser::bench_parse_socket_v6          378.69ns/iter  +/- 5.25  ->  274.82ns/iter +/- 0.95
net::addr_parser::bench_parse_socket_v6_scope_id 336.61ns/iter  +/- 2.36  ->  258.56ns/iter +/- 0.89
net::addr_parser::bench_parse_socketaddr_v4      118.20ns/iter  +/- 0.66  ->   78.86ns/iter +/- 0.22
net::addr_parser::bench_parse_socketaddr_v6      429.17ns/iter  +/- 5.70  ->  315.69ns/iter +/- 1.48

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 17, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 11 candidates
  • Random selection from 6 candidates

Comment thread library/core/src/net/parser.rs Outdated

@workingjubilee workingjubilee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, if joboet has an opinion otherwise, that's cool, but if we're going to hoist out the decimal implementation into its own thing, can't we just replace read_number with read_decimal and read_hex instead of this read_radix_max_digits function? It's only ever called with those two radixes and is internal anyways?

View changes since this review

Comment thread library/core/src/net/parser.rs Outdated
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 20, 2026
@rustbot

rustbot commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Split `read_number()` into seperate methods for the the `max_digits` `Some(_)`
and `None` cases.

Hoist reading the first digit which is always required.

The path for unlimited digits then no longer has to count digits at all.
@niklasf niklasf force-pushed the perf/addr-parser branch from 7255f6a to 1d54265 Compare June 21, 2026 08:29
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  IMAGE: x86_64-gnu-tools
##[endgroup]
    Updating crates.io index
error: failed to get `simd-adler32` as a dependency of package `miniz_oxide v0.8.8`
    ... which satisfies dependency `miniz_oxide = "^0.8.5"` of package `flate2 v1.1.9`
    ... which satisfies dependency `flate2 = "^1.1.9"` of package `citool v0.1.0 (/home/runner/work/rust/rust/src/ci/citool)`

Caused by:
  failed to load source for dependency `simd-adler32`

Caused by:

@niklasf

niklasf commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

replace read_number with read_decimal and read_hex

Tried that initially, but splitting across max_digits vs. unlimited appears to be more impactful than splitting across radix.

Other feedback applied and ready for the next round of review.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 21, 2026
@workingjubilee

Copy link
Copy Markdown
Member

can you quantify "more impactful"?

@workingjubilee

Copy link
Copy Markdown
Member

Or like, broadly describe even? "more impactful" doesn't really tell me anything.

@workingjubilee

Copy link
Copy Markdown
Member

And my apologies about the initial inquiry, I only felt compelled to ask because I truly felt baffled by the sentence. I was at various levels of "surely that's not what you meant?" with myself and "I have to ask, but...?" and the simplification/explained version is quite understandable.

@niklasf

niklasf commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

No worries, and thanks for still leaving a review in the first place.

read_hex() ends up with exactly one call-site in IPv6 parsing, while all the other features are still required for read_decimal(). Basically:

fn read_decimal<T: ReadNumberHelper + TryFrom<u32>>(&mut self, max_digits: Opton<usize>, allow_zero_prefix: bool) -> Option<T> { ... }
fn read_4_hex_digits(&mut self) -> Option<u16> { ... }

With that I measure:

net::addr_parser::bench_parse_ipaddr_v4           73.16ns/iter  +/- 1.39
net::addr_parser::bench_parse_ipaddr_v6_compress 217.49ns/iter  +/- 1.83
net::addr_parser::bench_parse_ipaddr_v6_full     336.63ns/iter +/- 10.53
net::addr_parser::bench_parse_ipaddr_v6_v4       255.87ns/iter  +/- 1.55
net::addr_parser::bench_parse_ipv4                71.75ns/iter  +/- 0.35
net::addr_parser::bench_parse_ipv6_compress      200.89ns/iter  +/- 0.78
net::addr_parser::bench_parse_ipv6_full          299.51ns/iter  +/- 1.16
net::addr_parser::bench_parse_ipv6_v4            229.38ns/iter  +/- 3.10
net::addr_parser::bench_parse_socket_v4           91.30ns/iter  +/- 0.30
net::addr_parser::bench_parse_socket_v6          282.56ns/iter  +/- 0.94
net::addr_parser::bench_parse_socket_v6_scope_id 264.66ns/iter  +/- 1.69
net::addr_parser::bench_parse_socketaddr_v4       93.73ns/iter  +/- 0.20
net::addr_parser::bench_parse_socketaddr_v6      326.19ns/iter  +/- 1.47

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2026

@workingjubilee workingjubilee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be a more "proper" way to rerun the PR CI but every time I am told about it I recall thinking, "That seems like more effort, though?"

read_hex() ends up with exactly one call-site in IPv6 parsing,

Right, I had an optimistic assumption that code duplication might actually be fine here for performance reasons.

It looks like the numbers are... rereads the tables a couple times. Oh. I see! That is indeed less impactful. The benchmarking framework itself is not exactly the best implementation of benchmarking, so I do wonder slightly about variance, but it's good enough that this is a clear improvement. Thanks!

...I wonder if it's because it's actually routing less logic through sufficiently-similar-looking codepaths so that LLVM infers the optimization is less important...? Or it's just not as easy for CSE/GVN...? Well, either way.

r? me
@bors r+

View changes since this review

@rust-bors

rust-bors Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 1d54265 has been approved by workingjubilee

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 23, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 24, 2026
…gjubilee

Optimize network address parser

Motivated by working with datasets of IP addresses.

First commit adds more examples for each case in the benchmark suite.

Second commit splits `read_number()` into seperate methods for the the `max_digits` `Some(_)` and `None` cases, which by itself significantly helps code generation.

Hoist reading the first digit which is always required.

The path for unlimited digits then no longer has to count digits at all.

Drive-by "fixes" the 10 digit debug assertion (which would be insufficient in base 16). Not actually used anywhere near the limit.

`./x bench library/coretests --test-args addr_parser` before -> after on AMD Ryzen 9 9950X:

    net::addr_parser::bench_parse_ipaddr_v4           81.73ns/iter  +/- 0.60  ->   62.36ns/iter +/- 0.12
    net::addr_parser::bench_parse_ipaddr_v6_compress 303.70ns/iter  +/- 1.29  ->  212.80ns/iter +/- 1.25
    net::addr_parser::bench_parse_ipaddr_v6_full     453.06ns/iter  +/- 7.89  ->  294.88ns/iter +/- 0.91
    net::addr_parser::bench_parse_ipaddr_v6_v4       301.41ns/iter  +/- 1.52  ->  224.82ns/iter +/- 0.99
    net::addr_parser::bench_parse_ipv4                87.24ns/iter  +/- 0.32  ->   52.94ns/iter +/- 0.33
    net::addr_parser::bench_parse_ipv6_compress      277.92ns/iter  +/- 3.29  ->  195.98ns/iter +/- 1.10
    net::addr_parser::bench_parse_ipv6_full          402.48ns/iter +/- 22.20  ->  276.37ns/iter +/- 4.05
    net::addr_parser::bench_parse_ipv6_v4            276.78ns/iter  +/- 1.18  ->  216.04ns/iter +/- 1.20
    net::addr_parser::bench_parse_socket_v4          105.18ns/iter  +/- 0.79  ->   69.20ns/iter +/- 0.46
    net::addr_parser::bench_parse_socket_v6          378.69ns/iter  +/- 5.25  ->  274.82ns/iter +/- 0.95
    net::addr_parser::bench_parse_socket_v6_scope_id 336.61ns/iter  +/- 2.36  ->  258.56ns/iter +/- 0.89
    net::addr_parser::bench_parse_socketaddr_v4      118.20ns/iter  +/- 0.66  ->   78.86ns/iter +/- 0.22
    net::addr_parser::bench_parse_socketaddr_v6      429.17ns/iter  +/- 5.70  ->  315.69ns/iter +/- 1.48
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 27 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158257 ( fix escaping placeholder check in next solver normalization folder)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)

Failed merges:

 - #158256 (Avoid parser panics bubbling out to proc macros)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 24, 2026
…gjubilee

Optimize network address parser

Motivated by working with datasets of IP addresses.

First commit adds more examples for each case in the benchmark suite.

Second commit splits `read_number()` into seperate methods for the the `max_digits` `Some(_)` and `None` cases, which by itself significantly helps code generation.

Hoist reading the first digit which is always required.

The path for unlimited digits then no longer has to count digits at all.

Drive-by "fixes" the 10 digit debug assertion (which would be insufficient in base 16). Not actually used anywhere near the limit.

`./x bench library/coretests --test-args addr_parser` before -> after on AMD Ryzen 9 9950X:

    net::addr_parser::bench_parse_ipaddr_v4           81.73ns/iter  +/- 0.60  ->   62.36ns/iter +/- 0.12
    net::addr_parser::bench_parse_ipaddr_v6_compress 303.70ns/iter  +/- 1.29  ->  212.80ns/iter +/- 1.25
    net::addr_parser::bench_parse_ipaddr_v6_full     453.06ns/iter  +/- 7.89  ->  294.88ns/iter +/- 0.91
    net::addr_parser::bench_parse_ipaddr_v6_v4       301.41ns/iter  +/- 1.52  ->  224.82ns/iter +/- 0.99
    net::addr_parser::bench_parse_ipv4                87.24ns/iter  +/- 0.32  ->   52.94ns/iter +/- 0.33
    net::addr_parser::bench_parse_ipv6_compress      277.92ns/iter  +/- 3.29  ->  195.98ns/iter +/- 1.10
    net::addr_parser::bench_parse_ipv6_full          402.48ns/iter +/- 22.20  ->  276.37ns/iter +/- 4.05
    net::addr_parser::bench_parse_ipv6_v4            276.78ns/iter  +/- 1.18  ->  216.04ns/iter +/- 1.20
    net::addr_parser::bench_parse_socket_v4          105.18ns/iter  +/- 0.79  ->   69.20ns/iter +/- 0.46
    net::addr_parser::bench_parse_socket_v6          378.69ns/iter  +/- 5.25  ->  274.82ns/iter +/- 0.95
    net::addr_parser::bench_parse_socket_v6_scope_id 336.61ns/iter  +/- 2.36  ->  258.56ns/iter +/- 0.89
    net::addr_parser::bench_parse_socketaddr_v4      118.20ns/iter  +/- 0.66  ->   78.86ns/iter +/- 0.22
    net::addr_parser::bench_parse_socketaddr_v6      429.17ns/iter  +/- 5.70  ->  315.69ns/iter +/- 1.48
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 24, 2026
…gjubilee

Optimize network address parser

Motivated by working with datasets of IP addresses.

First commit adds more examples for each case in the benchmark suite.

Second commit splits `read_number()` into seperate methods for the the `max_digits` `Some(_)` and `None` cases, which by itself significantly helps code generation.

Hoist reading the first digit which is always required.

The path for unlimited digits then no longer has to count digits at all.

Drive-by "fixes" the 10 digit debug assertion (which would be insufficient in base 16). Not actually used anywhere near the limit.

`./x bench library/coretests --test-args addr_parser` before -> after on AMD Ryzen 9 9950X:

    net::addr_parser::bench_parse_ipaddr_v4           81.73ns/iter  +/- 0.60  ->   62.36ns/iter +/- 0.12
    net::addr_parser::bench_parse_ipaddr_v6_compress 303.70ns/iter  +/- 1.29  ->  212.80ns/iter +/- 1.25
    net::addr_parser::bench_parse_ipaddr_v6_full     453.06ns/iter  +/- 7.89  ->  294.88ns/iter +/- 0.91
    net::addr_parser::bench_parse_ipaddr_v6_v4       301.41ns/iter  +/- 1.52  ->  224.82ns/iter +/- 0.99
    net::addr_parser::bench_parse_ipv4                87.24ns/iter  +/- 0.32  ->   52.94ns/iter +/- 0.33
    net::addr_parser::bench_parse_ipv6_compress      277.92ns/iter  +/- 3.29  ->  195.98ns/iter +/- 1.10
    net::addr_parser::bench_parse_ipv6_full          402.48ns/iter +/- 22.20  ->  276.37ns/iter +/- 4.05
    net::addr_parser::bench_parse_ipv6_v4            276.78ns/iter  +/- 1.18  ->  216.04ns/iter +/- 1.20
    net::addr_parser::bench_parse_socket_v4          105.18ns/iter  +/- 0.79  ->   69.20ns/iter +/- 0.46
    net::addr_parser::bench_parse_socket_v6          378.69ns/iter  +/- 5.25  ->  274.82ns/iter +/- 0.95
    net::addr_parser::bench_parse_socket_v6_scope_id 336.61ns/iter  +/- 2.36  ->  258.56ns/iter +/- 0.89
    net::addr_parser::bench_parse_socketaddr_v4      118.20ns/iter  +/- 0.66  ->   78.86ns/iter +/- 0.22
    net::addr_parser::bench_parse_socketaddr_v6      429.17ns/iter  +/- 5.70  ->  315.69ns/iter +/- 1.48
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 35 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #158336 (Stop excluding `stdarch` test crates from `rust-src`)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157419 (move rustc_type_ir Term things to term_kind.rs)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #157939 (Reorganize `tests/ui/issues` [8/N])
 - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public)
 - #158003 (Reorganize `tests/ui/issues` [9/N])
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158060 (Reorganize `tests/ui/issues` [10/N])
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158272 (Reorganize `tests/ui/issues` [13/N])
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)
 - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact)
 - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 35 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #158336 (Stop excluding `stdarch` test crates from `rust-src`)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157419 (move rustc_type_ir Term things to term_kind.rs)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #157939 (Reorganize `tests/ui/issues` [8/N])
 - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public)
 - #158003 (Reorganize `tests/ui/issues` [9/N])
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158060 (Reorganize `tests/ui/issues` [10/N])
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158272 (Reorganize `tests/ui/issues` [13/N])
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)
 - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact)
 - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 35 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #158336 (Stop excluding `stdarch` test crates from `rust-src`)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157419 (move rustc_type_ir Term things to term_kind.rs)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #157939 (Reorganize `tests/ui/issues` [8/N])
 - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public)
 - #158003 (Reorganize `tests/ui/issues` [9/N])
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158060 (Reorganize `tests/ui/issues` [10/N])
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158272 (Reorganize `tests/ui/issues` [13/N])
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)
 - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact)
 - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 35 pull requests

Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #158336 (Stop excluding `stdarch` test crates from `rust-src`)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157419 (move rustc_type_ir Term things to term_kind.rs)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #157939 (Reorganize `tests/ui/issues` [8/N])
 - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public)
 - #158003 (Reorganize `tests/ui/issues` [9/N])
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158060 (Reorganize `tests/ui/issues` [10/N])
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158272 (Reorganize `tests/ui/issues` [13/N])
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)
 - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact)
 - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 24, 2026
…gjubilee

Optimize network address parser

Motivated by working with datasets of IP addresses.

First commit adds more examples for each case in the benchmark suite.

Second commit splits `read_number()` into seperate methods for the the `max_digits` `Some(_)` and `None` cases, which by itself significantly helps code generation.

Hoist reading the first digit which is always required.

The path for unlimited digits then no longer has to count digits at all.

Drive-by "fixes" the 10 digit debug assertion (which would be insufficient in base 16). Not actually used anywhere near the limit.

`./x bench library/coretests --test-args addr_parser` before -> after on AMD Ryzen 9 9950X:

    net::addr_parser::bench_parse_ipaddr_v4           81.73ns/iter  +/- 0.60  ->   62.36ns/iter +/- 0.12
    net::addr_parser::bench_parse_ipaddr_v6_compress 303.70ns/iter  +/- 1.29  ->  212.80ns/iter +/- 1.25
    net::addr_parser::bench_parse_ipaddr_v6_full     453.06ns/iter  +/- 7.89  ->  294.88ns/iter +/- 0.91
    net::addr_parser::bench_parse_ipaddr_v6_v4       301.41ns/iter  +/- 1.52  ->  224.82ns/iter +/- 0.99
    net::addr_parser::bench_parse_ipv4                87.24ns/iter  +/- 0.32  ->   52.94ns/iter +/- 0.33
    net::addr_parser::bench_parse_ipv6_compress      277.92ns/iter  +/- 3.29  ->  195.98ns/iter +/- 1.10
    net::addr_parser::bench_parse_ipv6_full          402.48ns/iter +/- 22.20  ->  276.37ns/iter +/- 4.05
    net::addr_parser::bench_parse_ipv6_v4            276.78ns/iter  +/- 1.18  ->  216.04ns/iter +/- 1.20
    net::addr_parser::bench_parse_socket_v4          105.18ns/iter  +/- 0.79  ->   69.20ns/iter +/- 0.46
    net::addr_parser::bench_parse_socket_v6          378.69ns/iter  +/- 5.25  ->  274.82ns/iter +/- 0.95
    net::addr_parser::bench_parse_socket_v6_scope_id 336.61ns/iter  +/- 2.36  ->  258.56ns/iter +/- 0.89
    net::addr_parser::bench_parse_socketaddr_v4      118.20ns/iter  +/- 0.66  ->   78.86ns/iter +/- 0.22
    net::addr_parser::bench_parse_socketaddr_v6      429.17ns/iter  +/- 5.70  ->  315.69ns/iter +/- 1.48
rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
Rollup of 35 pull requests



Successful merges:

 - #158315 (`rust-analyzer` subtree update)
 - #158336 (Stop excluding `stdarch` test crates from `rust-src`)
 - #155739 (Add temporary scope to assert_eq and assert_ne)
 - #156885 (Fix misattributed type inference error span for index expressions)
 - #157271 (simplify some `proc_macro` things)
 - #157419 (move rustc_type_ir Term things to term_kind.rs)
 - #157883 (Remove strict invariant node_type on hir_type during ty privacy visit)
 - #157921 (trait solver: Resolve region vars in max universe)
 - #157960 (delegation: add support for infers in generics)
 - #157983 (Lift the same-signature restriction for `extern "tail"`)
 - #158053 (Optimize network address parser)
 - #158105 (Extract all instance shim variants into new `ShimKind` enum)
 - #158207 (Resolver: local/external split of  `resolve_ident_in_module_non_globs_unadjusted` )
 - #158279 (Follow goto and drop when linting unreachable code)
 - #157527 (Move derive tests into their dedicated folder)
 - #157807 (don't ice on non-lifetime binders under `-Zassumptions-on-binders`)
 - #157939 (Reorganize `tests/ui/issues` [8/N])
 - #157946 (Make `char::is_private_use` and `char::is_assigned` unstably public)
 - #158003 (Reorganize `tests/ui/issues` [9/N])
 - #158020 (Update mingw-w64 C toolchain)
 - #158039 (c-variadic: test that we use equality up to free lifetimes)
 - #158060 (Reorganize `tests/ui/issues` [10/N])
 - #158222 (format: ignore println newline in foreign format hints)
 - #158223 (Move target checking for #[lang] to the attribute parser)
 - #158252 (Use `cfg_select` in `std::os`)
 - #158263 (Only load the feature list once in the entire resolver)
 - #158267 (FromUtf8Error::into_utf8_lossy better example and suggest use)
 - #158272 (Reorganize `tests/ui/issues` [13/N])
 - #158274 (triagebot: Stop pinging myself)
 - #158282 (slice_split_once: bounds check optimization note)
 - #158300 (Improve unknown crate_type diagnostic suggestions)
 - #158304 (mailmap: update mu001999)
 - #158309 (Update `rustc-literal-escaper` version to `0.0.8`)
 - #158314 (Fix incorrect unsafe debug assertion in unchecked_div_exact)
 - #158326 (Add `io::ErrorKind::TooManyOpenFiles`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants