GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ipaddress: Speed up IPv4Address.ipv6_mapped by jstasiak · Pull Request #119814 · python/cpython

Conversation

@jstasiak

@jstasiak jstasiak commented May 30, 2024

Copy link
Copy Markdown
Contributor

A random find from my side, I was going through this code when I noticed some unnecessary conversions happening.

Nice performance improvement basically for free (numbers from my M1 Pro laptop):

In [1]: from ipaddress import IPv4Address, IPv6Address

In [2]: v4 = IPv4Address('10.0.0.1')

In [3]: IPv6Address(f'::ffff:{v4}') == IPv6Address((0xffff << 32) + v4._ip)
Out[3]: True

In [4]: %timeit IPv6Address(f'::ffff:{v4}')
3.63 µs ± 12 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

In [5]: %timeit IPv6Address((0xffff << 32) + v4._ip)
184 ns ± 0.413 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jstasiak
Speed up IPv4Address.ipv6_mapped (numbers instead of strings)
877eab1
A random find from my side, I was going through this code when I noticed
some unnecessary conversions happening.

Nice performance improvement basically for free (numbers from my M1 Pro
laptop):

    In [1]: from ipaddress import IPv4Address, IPv6Address

    In [2]: v4 = IPv4Address('10.0.0.1')

    In [3]: IPv6Address(f'::ffff:{v4}') == IPv6Address((0xffff << 32) + v4._ip)
    Out[3]: True

    In [4]: %timeit IPv6Address(f'::ffff:{v4}')
    3.63 µs ± 12 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

    In [5]: %timeit IPv6Address((0xffff << 32) + v4._ip)
    184 ns ± 0.413 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each)
@bedevere-app bedevere-app Bot added the awaiting review label May 30, 2024
@jstasiak

jstasiak commented May 30, 2024

Copy link
Copy Markdown
Contributor Author

I think this is small enough to not need an issue number. Since this is a 3.13+ feature I don't believe a news entry is needed either.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jstasiak jstasiak changed the title Speed up IPv4Address.ipv6_mapped (numbers instead of strings) Speed up IPv4Address.ipv6_mapped by removing unnecessary conversions May 30, 2024
@jstasiak jstasiak changed the title Speed up IPv4Address.ipv6_mapped by removing unnecessary conversions ipaddress: Speed up IPv4Address.ipv6_mapped May 30, 2024
@jstasiak jstasiak mentioned this pull request May 30, 2024
gh-109466: Add ipv6_mapped property to IPv4Address #109467
Merged
@github-actions

github-actions Bot commented Apr 16, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@jstasiak
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.