Skip to content

Speed up urllib.parse.quote() and quote_plus() for ASCII str inputs #163115

Backlog

Description

@gatewaytofredom

Feature or enhancement

urllib.parse.quote() and quote_plus() encode str inputs to bytes and delegate toquote_from_bytes(), which runs ''.join(map(quoter, bs)).

For exact ASCII str inputs with ASCII compatible encodings, bypassing that round-trip with str.rstrip() (all-safe) and str.translate() speeds up quote() by 1.25x–1.88x, quote_plus() by 2.0x–2.4x, and urlencode() by 1.7x, with negligible impact on fallback paths and import time.

Related: gh-160690 (ASCII fast path for unquote()).

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
    type-feature
    on Dec 3, 2026
  2. added a commit that references this issue on Dec 3, 2026
  3. picnixz commented on Dec 3, 2026

    @picnixz
    Member

    I do not think it is worth it. This is usually not the hot path in applications.

  4. picnixz commented on Dec 3, 2026

    @picnixz
    Member

    I am more worried about the extra complexity added to the code.

  5. reopened this on Dec 3, 2026
  6. added
    stdlib
    pending
    on Dec 3, 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

    pendingstdlibtype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions