Skip to content

Conversation

Flowdalic
Copy link
Member

Based on the initial analysis of Esteve Varela Colominas, the polling on join() with the fixed 100ms delay incurs a significant performance penalty, especially for short-lived processes. And since portage is prone to spawning many of those, the penalty adds up easily.

Instead of pooling proc.join() with a fixed 100ms delay, we now use the blocking variant of join() started in an executor which we await in the coroutine.

Before this change:

( cd lib; python3 -m timeit 'import portage.process; portage.process.spawn("true")' ) 
2 loops, best of 5: 104 msec per loop

After this change:

( cd lib; python3 -m timeit 'import portage.process; portage.process.spawn("true")' )
50 loops, best of 5: 4.45 msec per loop

Bug: https://bugs.gentoo.org/958635

Based on the initial analysis of Esteve Varela Colominas, the polling
on join() with the fixed 100ms delay incurs a significant performance
penalty, especially for short-lived processes. And since portage is
prone to spawning many of those, the penalty adds up easily.

Instead of pooling proc.join() with a fixed 100ms delay, we now use
the blocking variant of join() started in an executor which we await
in the coroutine.

Before this change:

( cd lib; python3 -m timeit 'import portage.process; portage.process.spawn("true")' )
2 loops, best of 5: 104 msec per loop

After this change:

( cd lib; python3 -m timeit 'import portage.process; portage.process.spawn("true")' )
50 loops, best of 5: 4.45 msec per loop

Bug: https://bugs.gentoo.org/958635
Signed-off-by: Florian Schmaus <[email protected]>
@mid-kid
Copy link
Contributor

mid-kid commented Aug 28, 2025

That was... deceptively simple. I have no idea where you found this option 😅
Thanks a lot for this!

@Flowdalic
Copy link
Member Author

Thanks a lot for this!

This was only possible because of your analysis. So thanks to you as well. :)

@thesamesam thesamesam requested a review from zmedico August 28, 2025 10:35
Copy link
Member

@zmedico zmedico left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks!

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