GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-124567: Reduce overhead of cycle GC. by markshannon · Pull Request #124717 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented Sep 27, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This PR makes the following changes to cycle GC, to reduce the overhead observed in #124567:

  • Does not form the transitive closure of the young generation before collecting it. Avoids scanning too much of the heap that is likely reachable.
  • Performs an amount of work proportional to the young collection in the incremental collection, avoiding n**2 performance on large heaps (this was a regression w.r.t. 3.12)
  • At the start of each full scan, mark all objects reachable from sys.modules, so they are not scanned this scan.
  • Computes the delta in heap size during incremental collection, and accelerates incremental collection if the heap is growing
  • Adds a _testinternalcapi.get_heap_size() function for more precise testing of the GC

Before merging, I need to:

  • Get performance numbers and stats for this version
  • Likewise for an alternative version that does form the transitive closure of the young generation, but only does so after marking reachable objects.
    I still need benchmarks and stats for this before merging.
  • Issue: Incremental GC causes a significant slowdown for Sphinx #124567

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
markshannon added 3 commits September 27, 2024 10:36
@markshannon
Attempt to match 3.12 in work done in GC
9d28e99
@markshannon
Lower scaling factor
d451ace
@markshannon
Pre-scan sys.modules
615a96e
@bedevere-app bedevere-app Bot mentioned this pull request Sep 27, 2024
Incremental GC causes a significant slowdown for Sphinx #124567
Closed
@markshannon markshannon closed this Sep 27, 2024
@markshannon markshannon reopened this Sep 27, 2024
@Privat33r-dev

Privat33r-dev commented Sep 28, 2024

Copy link
Copy Markdown
Contributor

As a quick preliminary check, I would suggest running doc tests, since they indicated the issue at first and caused further findings (see #118891 for details).

Currently, it appears to me that the PR achieves the opposite of its purpose.

Doctest on main branch takes ~12-15 minutes
With PR it takes >40m (still running): https://github.com/Privat33r-dev/cpython/actions/runs/11082906901/job/30796516669?pr=4
Main (before PR): https://github.com/Privat33r-dev/cpython/actions/runs/11083066610/job/30796883045?pr=5

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AA-Turner

AA-Turner commented Sep 28, 2024

Copy link
Copy Markdown
Member

The test at https://github.com/Privat33r-dev/cpython/actions/runs/11082906901/job/30796516669?pr=4 was killed by the 60 minute timeout, less than half-way through the build (source files not fully read). This PR isn't running documentation tests as no files in Doc/ have changed and there's no NEWS entry currently.

A

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Privat33r-dev

Privat33r-dev commented Sep 28, 2024

Copy link
Copy Markdown
Contributor

This PR isn't running documentation tests as no files in Doc/ have changed.

That's how I triggered it in my repo. I suggest to add/remove space in Docs in this PR as well, so we can see the end result of the changes.

I probably should've added further context for clarity. I used this PR as a base to make a PR in my repository, with 1 more commit from me (space change in docs), so Doctest will start automatically. It took more than 1 hour and stopped halfway through, because the job had 1 hour limit set.
Privat33r-dev#4

At the same time, I made a control Doctest in my repo on main branch + minor doc change. It took 13 m:
Privat33r-dev#5

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rruuaanng
rruuaanng reviewed Sep 29, 2024
View reviewed changes
Comment thread Python/gc.c
gc_list_merge(&survivors, visited);
assert(gc_list_is_empty(&increment));
gcstate->work_to_do += gcstate->heap_size / SCAN_RATE_DIVISOR / scale_factor;
Py_ssize_t delta = (gcstate->heap_size - gcstate->prior_heap_size)*3;

@rruuaanng rruuaanng Sep 29, 2024

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Binary operations, where two operands require spaces, may be more standard.
(gcstate->heap_size - gcstate->prior_heap_size) * 3

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@markshannon

markshannon commented Oct 1, 2024

Copy link
Copy Markdown
Member Author

Closing this, as we don't need an urgent fix (3.13 goes back to generational collection)

Longer term, I expect reduced reference counting operations to make faster-cpython/ideas#693 viable.

The pre-scan to find live objects is definitely worth further investigation, though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markshannon markshannon closed this Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@rruuaanng rruuaanng rruuaanng left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@markshannon @Privat33r-dev @AA-Turner @rruuaanng
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.