Improve performance of exception raise
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Funcionalidade
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- python
- Domínio
- backend, performance
Direção de pesquisa
The issue identifies _PyErr_SetObject() and _PyErr_SetRaisedException() as the relevant entry points; start by reading their implementations and the linked PR gh-160476. Compare the exception raising benchmarks described in the issue, including the free-threaded cases, and check whether the proposed direct call preserves the existing behavior. The linked PR indicates work is already underway.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Feature or enhancement
At the end of _PyErr_SetObject() the value is a normalized BaseException instance. The function still took a new reference to Py_TYPE(value) and fetched the value's traceback, only for _PyErr_Restore() to set that traceback back on the same object, store the value and drop the type again. Instead we can call _PyErr_SetRaisedException() directly.
Benchmarks
Default build, single thread:
| Benchmark | base | patch |
|---|---|---|
raise E / except E (heap type) |
174 ns | 171 ns: 1.02x faster |
raise E('message') / except E |
210 ns | 205 ns: 1.02x faster |
raise KeyError(1) / except KeyError (static type) |
192 ns | 176 ns: 1.09x faster |
d[1] / except KeyError (raised from C) |
177 ns | 170 ns: 1.04x faster |
f() / except E (raise through a frame) |
290 ns | 284 ns: 1.02x faster |
| Geometric mean | (ref) | 1.04x faster |
The gain is within binary layout noise range, but in the right direction.
Free-threaded build, N threads each running try: raise E / except E: pass with E defined
by the main thread:
| case | 1 thr | 2 thr | 4 thr | 8 thr |
|---|---|---|---|---|
ctl: isinstance(b, A) |
1.00 | 1.00 | 1.00 | 1.00 |
raise E / except E |
1.03-1.04 | 1.12-1.15 | 1.34-1.44 | 1.60-1.70 |
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-160476
- Linguagem predominante
- Python
- Estrelas
- 77.7k
- Forks
- 38.3k
- Merge médio
- 11h 58min
- PRs com merge (30d)
- 672
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o 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.
Mais de python/cpython
-
topic-socket type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python/cpython#160561 · 7 comentários ·
Mantenedores costumam responder em até 1 dia
-
tests topic-profiling type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
python/cpython#160334 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
extension-modules type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
Mantenedores costumam responder em até 1 dia
-
Remove unused FVS_* macrosAbertainterpreter-core type-feature
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 78/100
python/cpython#160109 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
extension-modules type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python/cpython#160001 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de python/cpython
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
GoogleCloudPlatform/gce-rescue#195 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
Mantenedores costumam responder em até 1 dia
-
intake mcp-intake needs-ac needs-human-review priority:medium
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 67/100
Ikalus1988/MisakaNet#3848 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 75/100
521xueweihan/HelloGitHub#4105 ·
-
bug size:XS
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
Mantenedores costumam responder em até 1 dia