python / python/cpython

Sampling mode for tracemalloc

Aberta
#150,494 2 comentários 0 reações 1 responsável Ver no GitHub

@corona10 já está trabalhando nisso.

Desde 3/6/2026.

extension-modules type-feature
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:

Tracemalloc tracks every allocation, which can be useful for debugging purposes, but imposes a high cost both in CPU (to collect the stacktrace for every allocation) and Memory (to store tracking metadata for every live object). In many cases, this overhead is unnecessary, and a statistical sample would be sufficient to explain both high memory consumption, as well as memory leaks.

I propose to add a poisson sampling mode to tracemalloc. In the common case, allocations would not be sampled, which means the CPU cost of tracemalloc would be just an increment and a comparison, while the additional memory cost would be 0. In cases where sampling does occur, the cost would be the same as before. The tracemalloc metadata would need to add an additional “weight” field to track the attributed weight of an allocation.

Has this already been discussed elsewhere?

This was discussed on the forum and got support from a core developer.

Links to previous discussion of this feature:

discuss.python.org/t/sampling-mode-for-tracemalloc/107333

Linked PRs
  • gh-151935

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.