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

Make CPU bound tasks synchronous in Chain #283

Merged
merged 4 commits into from
Feb 4, 2025
Merged

Make CPU bound tasks synchronous in Chain #283

merged 4 commits into from
Feb 4, 2025

Conversation

rustaceanrob
Copy link
Owner

@rustaceanrob rustaceanrob commented Feb 4, 2025

From my original understanding of async runtimes I thought you could slap an async on anything you expect to take some time to complete. After further reading, I don't think this is the correct approach for CPU-bound work that does not benefit from concurrency (unless by use of multiple threads but that is besides the point here). The additional context switching of adding a future that may or may not poll as ready might even add some overhead. Here I remove the async from CPU-bound functions to remove any unnecessary context switching.

Happy to let this one marinate for a little if there is some interest in actually profiling if this does anything. Although I don't think there will be any noticeable effect, I think it is good practice to remove the async from these functions.

ref: https://users.rust-lang.org/t/should-you-only-use-futures-for-i-o-bound-tasks/100784

cc @nyonson

Copy link
Contributor

@nyonson nyonson left a comment

Choose a reason for hiding this comment

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

ACK 3603114

@rustaceanrob rustaceanrob merged commit f61e307 into master Feb 4, 2025
14 checks passed
@rustaceanrob rustaceanrob deleted the sync-2-4 branch February 4, 2025 21:46
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.

2 participants