Intern string representation of operators and some other symbolic literals
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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-140235
- gh-151838
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Durchsicht des Vorschlags und der verknüpften PRs gh-140235 und gh-151838, wobei du dich auf den Parser, die AST-Konstruktion, die Bytecode-Generierung und die erwähnten REPL-Fälle konzentrierst. Das Issue legt keine endgültige Implementierung oder Akzeptanzkriterien fest; kläre anhand dieser Diskussionen den beabsichtigten Umfang und das erwartete Ergebnis, bevor du die Arbeit als abgeschlossen betrachtest.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 20/100