Skip to content

gh-137054: Remove obsolete counting of objects in young generation #137055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

sergey-miryanov
Copy link
Contributor

@sergey-miryanov sergey-miryanov commented Jul 23, 2025

I have found a dead code in gc.c for young generation.

cpython/Python/gc.c

Lines 1334 to 1342 in ec7fad7

#ifdef Py_STATS
{
Py_ssize_t count = 0;
PyGC_Head *gc;
for (gc = GC_NEXT(young); gc != young; gc = GC_NEXT(gc)) {
count++;
}
}
#endif

It is superseded by counting of object_visits via OBJECT_STAT_INC and adjusted gc_stats[gen].object_visits at the end of the collection.

cpython/Python/gc.c

Lines 2073 to 2079 in ec7fad7

#ifdef Py_STATS
if (_Py_stats) {
GC_STAT_ADD(generation, object_visits,
_Py_stats->object_stats.object_visits);
_Py_stats->object_stats.object_visits = 0;
}
#endif

I believe it is worth to remove dead code to decrease code base (yeah, by 9 lines).

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

- Now OBJECT_STAT_INC used to count and GC_STAT_ADD at the end of collect
  to adjust
@sergey-miryanov
Copy link
Contributor Author

I believe this should skip news.

@kumaraditya303 kumaraditya303 merged commit e93c30d into python:main Jul 24, 2025
48 checks passed
@sergey-miryanov
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy