python / python/cpython

Sampling mode for tracemalloc

Đang mở
#150,494 2 bình luận 0 reaction 1 người được giao Xem trên GitHub

@corona10 đang làm issue này rồi.

Từ ngày 3/6/2026.

extension-modules type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.