Python 为什么默认的gc生成阈值设置为(700, 10, 10)
Why the default gc generation threshold is set to (700, 10, 10) in Python
为什么在Python中默认GC生成阈值设置为(700, 10, 10);而且后两个数10、10这么小?
如此低的门槛会导致更多collections吗?
相对于上一代,阈值是乘数。来自 gc.set_threshold()
documentation:
In order to decide when to run, the collector keeps track of the number object allocations and deallocations since the last collection. When the number of allocations minus the number of deallocations exceeds threshold0
, collection starts. Initially only generation 0
is examined. If generation 0
has been examined more than threshold1
times since generation 1
has been examined, then generation 1
is examined as well. Similarly, threshold2
controls the number of collections of generation 1
before collecting generation 2
.
大胆强调我的。
如果第 0 代 运行 10 次,第 1 代仅 运行。由于第 0 代每 700(分配增量 - 释放)周期仅 运行s,这意味着第 1 代是每 10 * 700 == 7.000 个周期 运行。第 2 代 运行 每 10 * 10 * 700 == 70.000 个周期。
为什么在Python中默认GC生成阈值设置为(700, 10, 10);而且后两个数10、10这么小?
如此低的门槛会导致更多collections吗?
相对于上一代,阈值是乘数。来自 gc.set_threshold()
documentation:
In order to decide when to run, the collector keeps track of the number object allocations and deallocations since the last collection. When the number of allocations minus the number of deallocations exceeds
threshold0
, collection starts. Initially only generation0
is examined. If generation0
has been examined more thanthreshold1
times since generation1
has been examined, then generation1
is examined as well. Similarly,threshold2
controls the number of collections of generation1
before collecting generation2
.
大胆强调我的。
如果第 0 代 运行 10 次,第 1 代仅 运行。由于第 0 代每 700(分配增量 - 释放)周期仅 运行s,这意味着第 1 代是每 10 * 700 == 7.000 个周期 运行。第 2 代 运行 每 10 * 10 * 700 == 70.000 个周期。