Intern string representation of operators and some other symbolic literals
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza revisando la propuesta y los PR enlazados gh-140235 y gh-151838, centrándote en el parser, la construcción del AST, la generación de bytecode y los casos de REPL mencionados. El issue no define una implementación ni criterios de aceptación definitivos; confirma el alcance y el resultado previstos a partir de esas discusiones antes de considerar terminado el trabajo.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 20/100