Use tagged ints for faster iteration
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
Iteration over tuples and short lists is quite inefficient as we need to create an iterator object, only to have to destroy it again moments later. Not only that, fetching values from iterators involves additional indirection compared to fetching them from sequences.
Instead we can push a pair of values to the stack. For common sequences, like tuple, list, strings, some ranges and a few others, we push the sequence and the integer index (initially 0) to the stack. For other iterables, we push the iterator and NULL.
GET_ITER will have the signature:
iterable -- iter, index_or_null
FOR_ITER now has the signature:
iter, index_or_null -- iter, index_or_null, next.
What makes this efficient is tagged integers. By using tagged integers, no objects need to be created.
Examples
GET_ITER
[ <tuple at ...> ] -> [ <tuple at ...>, 0 ]
[ <file at ...> ] -> [ <file iterator at ...>, NULL ]
FOR_ITER
[ <tuple at ...>, 0 ] -> [ <tuple at ...>, 1, item0 ]
[ <file iterator at ...>, NULL ] -> [ <file iterator at ...>, NULL, line ]
Linked PRs
- gh-132555
- gh-132592
- gh-135063
- gh-135137
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
Comienza con los PRs vinculados gh-132555, gh-132592, gh-135063 y gh-135137 para determinar el estado actual de la implementación y, después, sigue las firmas de la pila de GET_ITER y FOR_ITER descritas aquí. Se considera terminado cuando las secuencias comunes usan índices enteros etiquetados sin objetos iteradores, mientras que los demás iterables conservan un iterador y NULL.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers, performance
- Tipo de issue
- Refactorización
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100