Intern string representation of operators and some other symbolic literals
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando la proposta e le PR collegate gh-140235 e gh-151838, concentrandoti sul parser, sulla costruzione dell’AST, sulla generazione del bytecode e sui casi di REPL menzionati. L’issue non definisce un’implementazione né criteri di accettazione definitivi; conferma l’ambito e il risultato previsti sulla base di queste discussioni prima di considerare il lavoro completato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 20/100