Skip to content

Commit b281fe8

Browse files
Remove statistics
1 parent 8b7fcd5 commit b281fe8

File tree

4 files changed

+11
-78
lines changed

4 files changed

+11
-78
lines changed

Include/internal/pycore_interp_structs.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ struct gc_collection_stats {
181181
Py_ssize_t collected;
182182
/* total number of uncollectable objects (put into gc.garbage) */
183183
Py_ssize_t uncollectable;
184-
Py_ssize_t untracked_tuples;
185184
};
186185

187186
/* Running stats per generation */
@@ -192,10 +191,6 @@ struct gc_generation_stats {
192191
Py_ssize_t collected;
193192
/* total number of uncollectable objects (put into gc.garbage) */
194193
Py_ssize_t uncollectable;
195-
Py_ssize_t untracked_tuples;
196-
Py_ssize_t total_untracked_tuples;
197-
Py_ssize_t total_tuples;
198-
Py_ssize_t tuples_by_size[33];
199194
};
200195

201196
enum _GCPhase {

Include/internal/pycore_tuple.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" {
1111
#include "pycore_object.h" // _PyObject_GC_IS_TRACKED
1212
#include "pycore_structs.h" // _PyStackRef
1313

14-
extern int _PyTuple_MaybeUntrack(PyObject *);
14+
extern void _PyTuple_MaybeUntrack(PyObject *);
1515
extern void _PyTuple_DebugMallocStats(FILE *out);
1616

1717
/* runtime lifecycle */

Objects/tupleobject.c

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,6 @@ class tuple "PyTupleObject *" "&PyTuple_Type"
2222

2323
static inline int maybe_freelist_push(PyTupleObject *);
2424

25-
static uint8_t
26-
_log2_int(Py_ssize_t size)
27-
{
28-
if (size == 0) {
29-
return 0;
30-
}
31-
32-
const uint64_t b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000, 0xFFFFFFFF00000000};
33-
const uint64_t S[] = {1, 2, 4, 8, 16, 32};
34-
35-
int64_t v = size;
36-
uint8_t r = 0; // result of log2(v) will go here
37-
for (int i = 5; i >= 0; i--) // unroll for speed...
38-
{
39-
if (v & b[i])
40-
{
41-
v >>= S[i];
42-
r |= S[i];
43-
}
44-
}
45-
46-
#ifdef Py_DEBUG
47-
uint8_t x = (uint8_t)log2((double)size);
48-
assert(x == r);
49-
#endif
50-
51-
return r + 1;
52-
}
53-
54-
static void
55-
_count_tuple(Py_ssize_t size)
56-
{
57-
PyInterpreterState *interp = _PyInterpreterState_GET();
58-
interp->gc.generation_stats[0].total_tuples += 1;
59-
uint8_t size_index = _log2_int(size);
60-
interp->gc.generation_stats[0].tuples_by_size[size_index] += 1;
61-
}
62-
6325

6426
/* Allocate an uninitialized tuple object. Before making it public, following
6527
steps must be done:
@@ -84,7 +46,6 @@ tuple_alloc(Py_ssize_t size)
8446
PyTupleObject *op = _Py_FREELIST_POP(PyTupleObject, tuples[index]);
8547
if (op != NULL) {
8648
_PyTuple_RESET_HASH_CACHE(op);
87-
_count_tuple(size);
8849
return op;
8950
}
9051
}
@@ -96,7 +57,6 @@ tuple_alloc(Py_ssize_t size)
9657
PyTupleObject *result = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size);
9758
if (result != NULL) {
9859
_PyTuple_RESET_HASH_CACHE(result);
99-
_count_tuple(size);
10060
}
10161
return result;
10262
}
@@ -108,7 +68,6 @@ tuple_alloc(Py_ssize_t size)
10868
static inline PyObject *
10969
tuple_get_empty(void)
11070
{
111-
_count_tuple(0);
11271
return (PyObject *)&_Py_SINGLETON(tuple_empty);
11372
}
11473

@@ -175,14 +134,14 @@ PyTuple_SetItem(PyObject *op, Py_ssize_t i, PyObject *newitem)
175134
return 0;
176135
}
177136

178-
int
137+
void
179138
_PyTuple_MaybeUntrack(PyObject *op)
180139
{
181140
PyTupleObject *t;
182141
Py_ssize_t i, n;
183142

184143
if (!PyTuple_CheckExact(op) || !_PyObject_GC_IS_TRACKED(op))
185-
return 0;
144+
return;
186145
t = (PyTupleObject *) op;
187146
n = Py_SIZE(t);
188147
for (i = 0; i < n; i++) {
@@ -192,10 +151,9 @@ _PyTuple_MaybeUntrack(PyObject *op)
192151
them yet. */
193152
if (!elt ||
194153
_PyObject_GC_MAY_BE_TRACKED(elt))
195-
return 0;
154+
return;
196155
}
197156
_PyObject_GC_UNTRACK(op);
198-
return 1;
199157
}
200158

201159
PyObject *
@@ -414,7 +372,7 @@ tuple_item(PyObject *op, Py_ssize_t i)
414372
}
415373

416374
PyObject *
417-
PyTuple_FromArray(PyObject *const *src, Py_ssize_t n)
375+
_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n)
418376
{
419377
if (n == 0) {
420378
return tuple_get_empty();

Python/gc.c

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -753,20 +753,18 @@ move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
753753
* and is much faster than a more complex approach that
754754
* would untrack all relevant tuples.
755755
*/
756-
static Py_ssize_t
756+
static void
757757
untrack_tuples(PyGC_Head *head)
758758
{
759-
Py_ssize_t untracked = 0;
760759
PyGC_Head *gc = GC_NEXT(head);
761760
while (gc != head) {
762761
PyObject *op = FROM_GC(gc);
763762
PyGC_Head *next = GC_NEXT(gc);
764763
if (PyTuple_CheckExact(op)) {
765-
untracked += _PyTuple_MaybeUntrack(op);
764+
_PyTuple_MaybeUntrack(op);
766765
}
767766
gc = next;
768767
}
769-
return untracked;
770768
}
771769

772770
/* Return true if object has a pre-PEP 442 finalization method. */
@@ -1378,7 +1376,7 @@ gc_collect_young(PyThreadState *tstate,
13781376
validate_spaces(gcstate);
13791377
PyGC_Head *young = &gcstate->young.head;
13801378
PyGC_Head *visited = &gcstate->old[gcstate->visited_space].head;
1381-
stats->untracked_tuples += untrack_tuples(young);
1379+
untrack_tuples(young);
13821380
GC_STAT_ADD(0, collections, 1);
13831381

13841382
PyGC_Head survivors;
@@ -1656,7 +1654,7 @@ gc_collect_increment(PyThreadState *tstate, struct gc_collection_stats *stats)
16561654
GC_STAT_ADD(1, collections, 1);
16571655
GCState *gcstate = &tstate->interp->gc;
16581656
gcstate->work_to_do += assess_work_to_do(gcstate);
1659-
stats->untracked_tuples += untrack_tuples(&gcstate->young.head);
1657+
untrack_tuples(&gcstate->young.head);
16601658
if (gcstate->phase == GC_PHASE_MARK) {
16611659
Py_ssize_t objects_marked = mark_at_start(tstate);
16621660
GC_STAT_ADD(1, objects_transitively_reachable, objects_marked);
@@ -1718,7 +1716,7 @@ gc_collect_full(PyThreadState *tstate,
17181716
PyGC_Head *young = &gcstate->young.head;
17191717
PyGC_Head *pending = &gcstate->old[gcstate->visited_space^1].head;
17201718
PyGC_Head *visited = &gcstate->old[gcstate->visited_space].head;
1721-
stats->untracked_tuples += untrack_tuples(young);
1719+
untrack_tuples(young);
17221720
/* merge all generations into visited */
17231721
gc_list_merge(young, pending);
17241722
gc_list_validate_space(pending, 1-gcstate->visited_space);
@@ -1758,7 +1756,7 @@ gc_collect_region(PyThreadState *tstate,
17581756
gc_list_init(&unreachable);
17591757
deduce_unreachable(from, &unreachable);
17601758
validate_consistent_old_space(from);
1761-
stats->untracked_tuples += untrack_tuples(from);
1759+
untrack_tuples(from);
17621760

17631761
/* Move reachable objects to next generation. */
17641762
validate_consistent_old_space(to);
@@ -2100,30 +2098,12 @@ _PyGC_Collect(PyThreadState *tstate, int generation, _PyGC_Reason reason)
21002098
default:
21012099
Py_UNREACHABLE();
21022100
}
2103-
gcstate->generation_stats[generation].untracked_tuples += stats.untracked_tuples;
2104-
gcstate->generation_stats[0].total_untracked_tuples += stats.untracked_tuples;
21052101
if (PyDTrace_GC_DONE_ENABLED()) {
21062102
PyDTrace_GC_DONE(stats.uncollectable + stats.collected);
21072103
}
21082104
if (reason != _Py_GC_REASON_SHUTDOWN) {
21092105
invoke_gc_callback(gcstate, "stop", generation, &stats);
21102106
}
2111-
else if (false) {
2112-
FILE *out = stderr;
2113-
2114-
fprintf(out, "GC[%d] total tuples : %zd\n", 0, gcstate->generation_stats[0].total_tuples);
2115-
fprintf(out, "GC[%d] total untracked_tuples : %zd\n", 0, gcstate->generation_stats[0].total_untracked_tuples);
2116-
for (int i = 0; i < 33; i++) {
2117-
fprintf(out, "GC[%d] by size %d : %zd\n", 0, i, gcstate->generation_stats[0].tuples_by_size[i]);
2118-
}
2119-
2120-
for (int i = 0; i < NUM_GENERATIONS; i++) {
2121-
fprintf(out, "GC[%d] collections : %zd\n", i, gcstate->generation_stats[i].collections);
2122-
fprintf(out, "GC[%d] collected : %zd\n", i, gcstate->generation_stats[i].collected);
2123-
fprintf(out, "GC[%d] uncollectable : %zd\n", i, gcstate->generation_stats[i].uncollectable);
2124-
fprintf(out, "GC[%d] untracked_tuples: %zd\n", i, gcstate->generation_stats[i].untracked_tuples);
2125-
}
2126-
}
21272107
_PyErr_SetRaisedException(tstate, exc);
21282108
GC_STAT_ADD(generation, objects_collected, stats.collected);
21292109
#ifdef Py_STATS

0 commit comments

Comments
 (0)