Use tagged ints for faster iteration
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelos PRs vinculados gh-132555, gh-132592, gh-135063 e gh-135137 para determinar o status atual da implementação e, em seguida, rastreie as assinaturas da pilha de GET_ITER e FOR_ITER descritas aqui. Está concluído quando sequências comuns usam índices inteiros marcados sem objetos iteradores, enquanto os demais iterables mantêm um iterador e NULL.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- compilers, performance
- Tipo de issue
- Refatoração
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 25/100