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 — Intern string representation of operators and some other symbolic literals · Issue #136757 · python/cpython

Intern string representation of operators and some other symbolic literals #136757

New issue
Copy link
New issue
Copy link
Open
Open
Intern string representation of operators and some other symbolic literals#136757
Copy link
Labels
easyinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

Description

@albertedwardson
albertedwardson
opened on Jul 18, 2025
Issue body actions

Feature or enhancement

Proposal:

Python currently interns certain strings, such as keywords and some ASCII/Unicode characters, as well as module-specific strings. I propose extending this interning mechanism to the string representations of operators (e.g., "+=", "==", "|=").

Rationale:
Interning these strings could improve performance, particularly in code parsing workflows, by:

  • Reducing memory overhead for repeated operator strings.
  • Accelerating string comparisons (e.g., during AST construction or bytecode generation).

Target Symbols:
The following multi-character syntactic literals (with len() > 1) are candidates for interning:

# Syntax literals  
'...', '->' 

# Operators  
'**', '//', '==', '!=', '>=', '<=', ':=',  
'+=', '-=', '*=', '/=', '//=', '%=', '**=',  
'<<', '>>', '<<=', '>>=', '&=', '|=', '^='  

# And maybe character sequence that used in REPL?
'>>>'

Considerations:

  • The change would be low-risk, as it targets immutable, statically known strings.
  • The impact on startup time and memory usage should be negligible, given the small set of operators.

Would this be a worthwhile optimization for CPython? I’d appreciate feedback on the idea and the PoC.

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

  • gh-136757: More immortal strings #140235
  • gh-136757: Reuse static strings for exact operator tokens #151838

Activity

  1. albertedwardson
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jul 18, 2025
  2. albertedwardson
    changed the title [-]Intern string representation of operators[/-] [+]Intern string representation of operators and some other symbolic literals[/+] on Jul 18, 2025
  3. StanFromIreland
    added
    performancePerformance or resource usagePerformance or resource usage
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Jul 18, 2025
  4. StanFromIreland commented on Jul 18, 2025

    @StanFromIreland
    StanFromIreland
    on Jul 18, 2025
    Member
    More actions

    Are you able to provide benchmarks?

  5. albertedwardson commented on Jul 18, 2025

    @albertedwardson
    albertedwardson
    on Jul 18, 2025
    ContributorAuthor
    More actions

    Thanks for the feedback! I’m currently looking into how to properly benchmark this. I haven’t run the full pyperformance suite yet, but I’m planning to get familiar with it and set it up properly.

    In the meantime, would some synthetic microbenchmarks (e.g. repeated AST parsing or string comparison tests) be acceptable as a starting point? I can begin with those while I work toward running more representative, full-suite benchmarks.

  6. ZeroIntensity commented on Jul 20, 2025

    @ZeroIntensity
    ZeroIntensity
    on Jul 20, 2025
    Member
    More actions

    In the meantime, would some synthetic microbenchmarks (e.g. repeated AST parsing or string comparison tests) be acceptable as a starting point?

    Yeah, that'd be great.

    I think the change is simple enough that it's worth doing if there are any noticeable performance/memory improvements.

    Reacted by Albert Eduardovich N.
  7. albertedwardson commented on Jul 21, 2025

    @albertedwardson
    albertedwardson
    on Jul 21, 2025
    ContributorAuthor
    More actions

    I will continue doing this in a week, now I don’t have the opportunity

  8. StanFromIreland
    added
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Jun 14, 2026
  9. StanFromIreland commented on Jun 14, 2026

    @StanFromIreland
    StanFromIreland
    on Jun 14, 2026
    Member
    More actions

    A little ping, as it has been almost a year :-)

  10. StanFromIreland
    closed this as not plannedon Jun 20, 2026
  11. ZeroIntensity
    reopened this on Jun 20, 2026
  12. ZeroIntensity commented on Jun 20, 2026

    @ZeroIntensity
    ZeroIntensity
    on Jun 20, 2026
    Member
    More actions

    I think this is still worthwhile, even if the original author has disappeared. Let's apply "easy" for a newcomer to take a stab at this.

  13. ZeroIntensity
    added
    easy
    and removed
    pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
    on Jun 20, 2026
  14. albertedwardson commented on Jun 20, 2026

    @albertedwardson
    albertedwardson
    on Jun 20, 2026
    ContributorAuthor
    More actions

    hi guys
    yeah, sorry
    i just thought it wouldn't bring any significant improvements anyway, so I abandoned the idea without conducting any benchmarks

  15. omkar-334 commented on Jun 20, 2026

    @omkar-334
    omkar-334
    on Jun 20, 2026
    Contributor
    More actions

    hi guys, can i try to work on this

  16. ZeroIntensity commented on Jun 20, 2026

    @ZeroIntensity
    ZeroIntensity
    on Jun 20, 2026
    Member
    More actions

    Go for it, feel free to tag me for a review.

    Reacted by Omkar Kabde
  17. omkar-334
    added a commit that references this issue on Jun 21, 2026

    Merge branch 'main' into pythongh-136757-intern-operator-strings

    4a65219
  18. hanamuura commented on Oct 28, 2026

    @hanamuura
    hanamuura
    on Oct 28, 2026
    More actions

    16. hi guys, can i try to work on this

    hi. are you still working on it?

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

    easyinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.