Optimize `frozenset` construction
Abierto
@ZeroIntensity ya está trabajando en esto.
Desde el 18/5/2026.
performance
sprint
type-feature
- 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:
Many cases of frozenset look like this:
xyz = frozenset({1, 2, 3})
Currently, this constructs a new frozenset and copies the set object created by the literal. We can optimize this by detecting that it's a set literal via PyUnstable_Object_IsUniqueReferencedTemporary, and then simply move the mutable set 's memory into the frozenset without a copy.
Additionally, we have some optimizations for generator expressions inside sets. For example, this will be optimized by the compiler into some bytecode magic:
xyz = set((index for index in range(5))
We can extend this optimization to frozensets as well.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
Linked PRs
- gh-150028
- gh-153807
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.
Evaluación
Este issue todavía no se ha evaluado.