Skip to content
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

fix: async access to gil updates; notes on perf #159

Merged
merged 7 commits into from
Feb 12, 2025
Merged

Conversation

ryanolson
Copy link
Contributor

What does the PR do?

  • improved error handling on deserialize
  • offloading gil access on tokio async threads to help avoid starvation
    • this has extra overhead
    • does not fully solve all problems as there are still some rust bits that could add cpu overheads

grahamking
grahamking previously approved these changes Feb 12, 2025
let generator = self.generator.clone();
let event_loop = self.event_loop.clone();

let stream = tokio::task::spawn_blocking(move || {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a small comment here for future newbie readers here? For example, (correct me where I'm wrong), is the key point of this block's diff that it is putting the Python GIL acquisition onto a dedicated task that won't block the async runtime - whereas previously is was blocking the runtime?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a very subtle but important detail to the overall system performance that could just look like a simple indentation to the right from the previous code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I added a comment in the top-level readme, but i'll add a note here.

This does add overheads. Under low GIL contention, this is more expensive, because we have to schedule another a task on a blocking thread pool, then await it.

Under high GIL contentions, we need to offload it or we will strongly block the async threads.

No way to know, so we pay the price of the GIL - this time two fold.

Copy link
Contributor

@rmccorm4 rmccorm4 Feb 12, 2025

Choose a reason for hiding this comment

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

I meant can we put a comment like that (similar to README) co-located inline with the code here when someone is scanning through how the code works?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not blocking (pun intended), but I think it would be useful

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a293ed9

fixed here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

merged too quick. added to the next PR.

@ryanolson ryanolson merged commit 6e69d6e into main Feb 12, 2025
6 checks passed
@ryanolson ryanolson deleted the ryan/gil-misc branch February 12, 2025 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants