Remove Incref/Decref of Specific Immortal Objects
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Feature or enhancement
Proposal:
In various places we incref or decref an object that we already know is a specific immortal object, like None. For example, see gh-117393. These operations are unnecessary and the (small) cost can be avoided.
We could simply drop the increfs and decrefs, but there is value in communicating that we would have done the op if the object weren't known to be immortal. (Furthermore, there's the very, very remote chance that some known-immortal object might be made mortal again some day, for some currently unknown reason. It would be quite hard at the point to know that we should add back in the incref or decref we had removed.)
Here are the options I see:
- leave the existing code alone
- replace the existing code with comments
- replace the existing code with a noop macro (in the internal API)
We probably wouldn't make all the changes we could find all at once, but could at the least point to this issue for the decision on what should be done. If we do add a macro then we'd do it relative to this issue.
Personally, I'd go with the macro. It would communicate the intent to readers just as well as the existing code does or as a comment would. I imagine it would look something like the following:
#ifdef Py_DEBUG
# define Py_INCREF_IMMORTAL(OBJ) \
assert(_Py_IsImmortal(OBJ)
# define Py_DECREF_IMMORTAL(OBJ) \
assert(_Py_IsImmortal(OBJ)
#else
# define Py_INCREF_IMMORTAL(OBJ)
# define Py_DECREF_IMMORTAL(OBJ)
#endif
For None we could be even more explicit:
#define Py_INCREF_NONE() \
Py_INCREF_IMMORTAL(Py_None)
#define Py_DECREF_NONE() \
Py_DECREF_IMMORTAL(Py_None)
// or
#define Py_INCREF_NONE(OBJ) \
do { \
assert(OBJ == Py_None) \
Py_INCREF_IMMORTAL(OBJ) \
} while (0)
#define Py_DECREF_NONE(OBJ) \
do { \
assert(OBJ == Py_None) \
Py_DECREF_IMMORTAL(OBJ) \
} while (0)
CC @eduardo-elizondo
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response
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 pela proposta e pela discussão gh-117393 referenciada; em seguida, localize as operações incref/decref existentes em immortal objects conhecidos. Compare as três opções apresentadas, incluindo o comportamento proposto de Py_DEBUG, e estabeleça qual escolha de API e qual escopo seriam considerados concluídos; o issue não nomeia arquivos nem testes.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- c
- Domínio
- backend
- Tipo de issue
- Funcionalidade
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Estagnada
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 25/100