Condition for garbage collection #159
Replies: 1 comment 3 replies
-
Thanks for the info! It looks like you put a good amount of time into this analysis, which everyone appreciates. It sounds like you are saying that by manually advancing the GC generation in certain places we can get improved GC behavior, as well as better CPU and memory performance. Did I understand that right? Just to be sure, would you mind adding a brief summary of your key observation/proposal at the top of your original post, just so there's no confusion? Thanks! Also, I'm afraid I'm missing some context. Would you mind filling in the gaps for me for the parts below?
What is the full command you used?
Is that CPython code or some declarative query or what? Where does that code go?
Where does one set that? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Brief summary
I collected the triggers of garbage collection on the pyperformance (running with
--process 1
),The collection rate for many cases is very low, indicating that a lot of objects were scanned, but collection occurred on a small portion.
Most objects can be cleaned by simple reference counting, gc handle unreachable reference cycles.
Count for gc trigger increases in
_PyObject_GC_Alloc
, this represents an assumption that the more objects alloc, the more reference cycles. However, the correlation between the two may be very weak.Theoretically, only if a
container object
ref to anothercontainer object
, reference cycles maybe happen. So, I added a new metric to the statistics.The above code indicates if a reference assignment occurs and the value is a
container object
, gc count inc.In CPython is equivalent to the following determination.
A similar case is list_append, dict_set_item, and so on.
The following table shows the performance when the threshold is set to ( 10_000, 10, 10 )
The CPU performance also improved.
I'm testing the memory footprint and a simple test shows no significant increase.
In addition, maybe more precise metrics and thresholds to get better results.
Beta Was this translation helpful? Give feedback.
All reactions