Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit af24cd7

Browse files
committed
Revert alternating collections. Do incremental collection directly after young collection.
1 parent a8834d3 commit af24cd7

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

Include/internal/pycore_gc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ struct _gc_runtime_state {
205205
Py_ssize_t incremental_gc_progress;
206206
/* Which of the old spaces is the aging space */
207207
int aging_space;
208-
int incremental_next;
209208
};
210209

211210

Include/internal/pycore_runtime_init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ extern PyTypeObject _PyExc_MemoryError;
150150
}, \
151151
.gc = { \
152152
.enabled = 1, \
153-
.young = { .threshold = 1000, }, \
153+
.young = { .threshold = 2000, }, \
154154
.old = { \
155155
{ .threshold = 10, }, \
156156
{ .threshold = 10, }, \

Modules/gcmodule.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,28 +2526,36 @@ _Py_RunGC(PyThreadState *tstate)
25262526
if (_py_stats) {
25272527
_py_stats->object_stats.object_visits = 0;
25282528
}
2529-
int stats_gen = gcstate->incremental_next ? NUM_GENERATIONS : 0;
25302529
#endif
25312530

25322531
gcstate->collecting = 1;
25332532
struct gc_collection_stats stats = { 0 };
2533+
GC_STAT_ADD(0, collections, 1);
25342534

2535-
GC_STAT_ADD(stats_gen, collections, 1);
2535+
invoke_gc_callback(gcstate, "start", 0, &stats);
2536+
gc_collect_young(tstate, &stats);
2537+
invoke_gc_callback(gcstate, "stop", 0, &stats);
2538+
GC_STAT_ADD(0, objects_collected, stats.collected);
25362539

2537-
invoke_gc_callback(gcstate, "start", gcstate->incremental_next, &stats);
2538-
if (gcstate->incremental_next) {
2539-
gc_collect_increment(tstate, &stats);
2540-
gcstate->young.count = 0;
2541-
}
2542-
else {
2543-
gc_collect_young(tstate, &stats);
2540+
#ifdef Py_STATS
2541+
if (_py_stats) {
2542+
GC_STAT_ADD(0, object_visits,
2543+
_py_stats->object_stats.object_visits);
2544+
_py_stats->object_stats.object_visits = 0;
25442545
}
2545-
invoke_gc_callback(gcstate, "stop", gcstate->incremental_next, &stats);
2546+
#endif
2547+
2548+
stats = (struct gc_collection_stats){ 0 };
2549+
GC_STAT_ADD(1, collections, 1);
2550+
2551+
invoke_gc_callback(gcstate, "start", 0, &stats);
2552+
gc_collect_increment(tstate, &stats);
2553+
invoke_gc_callback(gcstate, "stop", 0, &stats);
2554+
GC_STAT_ADD(1, objects_collected, stats.collected);
25462555

2547-
GC_STAT_ADD(stats_gen, objects_collected, stats.collected);
25482556
#ifdef Py_STATS
25492557
if (_py_stats) {
2550-
GC_STAT_ADD(stats_gen, object_visits,
2558+
GC_STAT_ADD(1, object_visits,
25512559
_py_stats->object_stats.object_visits);
25522560
_py_stats->object_stats.object_visits = 0;
25532561
}

Python/specialize.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ print_gc_stats(FILE *out, GCStats *stats)
208208
{
209209
for (int i = 0; i < NUM_GENERATIONS+1; i++) {
210210
fprintf(out, "GC[%d] collections: %" PRIu64 "\n", i, stats[i].collections);
211+
fprintf(out, "GC[%d] objects queued: %" PRIu64 "\n", i, stats[i].objects_queued);
211212
fprintf(out, "GC[%d] object visits: %" PRIu64 "\n", i, stats[i].object_visits);
212213
fprintf(out, "GC[%d] objects collected: %" PRIu64 "\n", i, stats[i].objects_collected);
213214
}

Tools/scripts/summarize_stats.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def calculate_gc_stats(stats):
506506
gc_stats.append({})
507507
gc_stats[gen_n][name] = value
508508
return [
509-
(i, gen["collections"], gen["objects collected"], gen["object visits"])
509+
(i, gen["collections"], gen["objects queued"], gen["objects collected"], gen["object visits"])
510510
for (i, gen) in enumerate(gc_stats)
511511
]
512512

@@ -524,7 +524,7 @@ def emit_comparative_object_stats(base_stats, head_stats):
524524
def emit_gc_stats(stats):
525525
with Section("GC stats", summary="GC collections and effectiveness"):
526526
rows = calculate_gc_stats(stats)
527-
emit_table(("Generation:", "Collections:", "Objects collected:", "Object visits:"), rows)
527+
emit_table(("Generation:", "Collections:", "Objects queued:", "Objects collected:", "Object visits:"), rows)
528528

529529
def emit_comparative_gc_stats(base_stats, head_stats):
530530
with Section("GC stats", summary="GC collections and effectiveness"):
@@ -533,6 +533,7 @@ def emit_comparative_gc_stats(base_stats, head_stats):
533533
emit_table(
534534
("Generation:",
535535
"Base collections:", "Head collections:",
536+
"Base objects queued:", "Head objects queued:",
536537
"Base objects collected:", "Head objects collected:",
537538
"Base object visits:", "Head object visits:"),
538539
join_rows(base_rows, head_rows))

0 commit comments

Comments
 (0)