Skip to content

macos get_interfaces is extremly slow with larger amount of interfaces (sometimes) #143

Closed

Description

@dignifiedquire

I am currently debugging a slow down in gathering network interfaces, and found the following

If I modify to the list_interfaces example to measure the time it takes for the call to get_interfaces I get the following results

Default implementation on macos

  • got interfaces 21 after 3.3814s (sometimes this is even more, I have seen up to 15 seconds)

When I use ifconfig the results are instant. So I looked at https://github.com/apple-oss-distributions/network_cmds/blob/main/ifconfig.tproj/ifconfig.c and found it uses getifaddr instead of the framework APIs currently being used.

I then switched the call in interfaces::interfaces() to use

crate::os::unix::interface::unix_interfaces()

instead and got in the example a much more reasonable

  • got interfaces 21 after 0.0003s

Activity

  1. shellrow commented on Dec 13, 2025

    @shellrow
    Owner

    Thanks for the report and the investigation!

    One clarification from the current codebase: on macOS, interfaces() already uses getifaddrs via unix_interfaces() to enumerate interfaces. However, we also call get_if_type_map() to enrich the data (interface type and display name), and get_if_type_map() internally uses system_configuration::network_configuration::get_interfaces().

    So even though the base interface listing itself is fast, the SystemConfiguration lookup still runs each time and may block depending on the environment (for example, configd state, VPNs, or Network Extensions).

    I also measured a detailed breakdown on my machines (24 interfaces present), which makes the bottleneck very clear:

    • Time taken to build SCInterface map (SystemConfiguration): ~13.7 ms
    • Time taken to enumerate unix interfaces via getifaddrs: ~0.8 ms
    • Total time for interfaces() (24 interfaces): ~15.5 ms

    So the vast majority of the time is spent inside the SystemConfiguration-based lookup. And it’s clear that if network_configuration::get_interfaces() blocks, the total call time will scale accordingly.

    We’ll next look into how to avoid this slow path by default while keeping interface type/name information available when possible.

  2. dignifiedquire commented on Dec 13, 2025

    @dignifiedquire
    ContributorAuthor

    Thanks for the quick reply. Following up I did some measurements on my machine, and can confirm your numbers

    network_configuration::get_interfaces: 1758ms
    get_if_type_map: 1948ms
    unix_interfaces: 0ms
    gateway_map: 0ms
    assign gateway: 0ms
    default iface/dns_servers: 0ms
    got interfaces 21 after 1.9491s
    

    (funny enough, today it got a bit faster again)

  3. linked a pull request that will close this issueperf(macos): speed up interface enumeration #144on Dec 14, 2025
  4. shellrow commented on Dec 14, 2025

    @shellrow
    Owner

    Thanks for running the measurements!

    I've implemented a performance improvement on the perf(macos): speed up interface enumeration #144 .

    Benchmark results on my machine (22 interfaces):
    Before (release):

    • Total: ~13–15 ms

    After (release):

    • Total: ~1.9–2.0 ms

    This is 7x speed improvement, with the interface-type and friendly-name resolution itself becoming ~40x faster.

    Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions