Skip to content

IpAddr::from_str is unnecessarily slow for IPv6 addresses #94825

Open
@jyn514

Description

@jyn514

from_str is implemented like so:

/// Read an IP Address, either IPv4 or IPv6.
fn read_ip_addr(&mut self) -> Option<IpAddr> {
self.read_ipv4_addr().map(IpAddr::V4).or_else(move || self.read_ipv6_addr().map(IpAddr::V6))
}

This unnecessarily penalizes ipv6 addresses, because the parser will always do a full linear scan of the input before it even starts to parse the address. Instead, it could use the knowledge that IPv4 addresses are at most 15 bytes long to skip directly to read_ipv6_addr for longer strings.

@rustbot label: +I-slow +T-libs +C-enhancement

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.I-slowIssue: Problems and improvements with respect to performance of generated code.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions