Skip to content

importlib.metadata: Use str.translate to improve performance of importlib.metadata.Prepared.normalized #143658

Closed

Description

@hugovk

Feature or enhancement

Proposal:

We can apply @henryiii's improvement to packaging in pypa/packaging#1030 (see also https://iscinumpy.dev/post/packaging-faster/) to improve the performance of canonicalize_name and make it ~3.7 times faster.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Jan 10, 2026
  2. changed the title [-]importlib.metadata: Use `translate` to improve performance of `canonicalize_name`[/-] [+]importlib.metadata: Use `translate` to improve performance of `importlib.metadata.Prepared.normalized`[/+] on Jan 10, 2026
  3. changed the title [-]importlib.metadata: Use `translate` to improve performance of `importlib.metadata.Prepared.normalized`[/-] [+]importlib.metadata: Use `str.translate` to improve performance of `importlib.metadata.Prepared.normalized`[/+] on Jan 10, 2026
  4. added a commit that references this issue on Jan 13, 2026
  5. added a commit that references this issue on Feb 6, 2026
  6. added 2 commits that reference this issue on Feb 15, 2026
  7. jaraco commented on Mar 20, 2026

    @jaraco
    Member

    We can apply @henryiii's improvement to packaging in pypa/packaging#1030 (see also https://iscinumpy.dev/post/packaging-faster/) to improve the performance of canonicalize_name and make it ~3.7 times faster.

    Let it be stated that the referenced blog provides the rationale why this change is valuable.

  8. jaraco commented on Mar 20, 2026

    @jaraco
    Member

    In python/importlib_metadata#533 (comment), I measured the performance benefit and find that it saves ~300 ns per call (on an M3 Mac pro). It's going to take a lot of calls to recoup the value from this change, and most users are never going to notice the benefit. Is there any known use case where we know users will benefit meaningfully from this change?

  9. added a commit that references this issue on Apr 25, 2026
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

    performancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytopic-importlibtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions