Skip to content
New issue

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

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

Already on GitHub? # to your account

Reduce fiber switches by queuing callbacks for each tick #34

Merged
merged 8 commits into from
Jan 10, 2022

Conversation

kelunik
Copy link
Member

@kelunik kelunik commented Jan 9, 2022

This massively reduces the number of fibers switches. Before, we usually had a switch to the event loop, another to the callback fiber, called Suspension::resume(), switched back to the event loop, switched to the microtask fiber, switched to the fiber that suspended to await an event. Now we switch to the event loop, switch to the callback fiber once per tick (if non-blocking and there's no suspend within the callback) and switch to the original fiber.

@kelunik kelunik requested a review from trowski January 9, 2022 22:10
@kelunik kelunik added this to the 0.2.0 milestone Jan 9, 2022
@kelunik kelunik requested a review from WyriHaximus January 9, 2022 22:21
@trowski
Copy link
Member

trowski commented Jan 9, 2022

@WyriHaximus FYI, this has a noticeable performance improvement (+10% to 15% on an HTTP server test) when many watchers are set to be invoked within a single tick.

Copy link
Contributor

@bwoebi bwoebi left a comment

Choose a reason for hiding this comment

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

I like this change a lot - thanks for the effort :-)

@kelunik
Copy link
Member Author

kelunik commented Jan 10, 2022

@trowski I'm seeing 24-25% performance improvement instead of 10-15% for amphp/http-server's hello-world.php.

Copy link
Contributor

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

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

Great work 👍

@kelunik kelunik merged commit eb2d6f8 into main Jan 10, 2022
@kelunik kelunik deleted the reduced-fiber-switches branch January 10, 2022 19:56
@trowski
Copy link
Member

trowski commented Jan 10, 2022

@trowski I'm seeing 24-25% performance improvement instead of 10-15% for amphp/http-server's hello-world.php.

Wow! Even better! I was running a debug build of PHP, so take my benchmark with a grain of salt. 😁

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants