Skip to content

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Oct 17, 2025

This PR:

  • Counts number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead
  • Does not track most untrackable tuples during creation. This prevents large numbers of small tuples causing excessive GCs.

For the example in the original report this makes performance on main a bit better than 3.13.

Benchmarking results show this is about neutral on performance otherwise.

* Count number of actually tracked objects, instead of trackable objects. This ensures that untracking tuples has the desired effect of reducing GC overhead
* Do not track most untrackable tuples during creation. This prevents large numbers of small tuples causing execessive GCs.
@sergey-miryanov
Copy link
Contributor

I'm not sure I get what android (x86_64) fails.
I can propose two solutions:

  1. Change default value for work_to_do from -5000 to 0
  2. Or remove newly added condition
if (gcstate->work_to_do < 0) {
    return;
}

@mhsmith
Copy link
Member

mhsmith commented Oct 19, 2025

I'm not at all familiar with the garbage collector, but one of the ways that Android differs from the other platforms is that it runs all the test suite serially in a single process.

}
intptr_t new_objects = gcstate->young.count;
intptr_t max_heap_fraction = new_objects*3/2;
intptr_t max_heap_fraction = new_objects*2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above is not in line with this one, but I don't want to stop this PR from merge now. We can fix this in follow up PR.

Copy link
Contributor

@sergey-miryanov sergey-miryanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, thanks!

@sergey-miryanov
Copy link
Contributor

sergey-miryanov commented Oct 21, 2025

Should we redo the benchmarks to see how the final version impacts performance? Maybe we can run it on https://github.com/faster-cpython/benchmarking-public (but I don't know how).

Comment on lines +247 to +248
PyThreadState *tstate = _PyThreadState_GET();
struct _gc_runtime_state *gcstate = &tstate->interp->gc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PyThreadState *tstate = _PyThreadState_GET();
struct _gc_runtime_state *gcstate = &tstate->interp->gc;
struct _gc_runtime_state *gcstate = &_PyInterpreterState_GET()->gc;

Maybe it'll be better to use the same expression as below?
There's no another call of _PyThreadState_GET in this file.

small tuples.

* Counts number of actually tracked objects, instead of trackable objects.
This ensures that untracking tuples has the desired effect of reducing GC overhead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This ensures that untracking tuples has the desired effect of reducing GC overhead
This ensures that untracking tuples has the desired effect of reducing GC overhead.

Comment on lines +159 to +160
/* Fast, but conservative check if an object maybe tracked
May return true for an object that is not tracked,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* Fast, but conservative check if an object maybe tracked
May return true for an object that is not tracked,
/* Fast, but conservative check if an object maybe tracked.
May return true for an object that is not tracked.

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.

5 participants