Skip to content

Make CPU bound tasks synchronous in Chain#283

Merged
rustaceanrob merged 4 commits intomasterfrom
sync-2-4
Feb 4, 2025
Merged

Make CPU bound tasks synchronous in Chain#283
rustaceanrob merged 4 commits intomasterfrom
sync-2-4

Conversation

@rustaceanrob
Copy link
Collaborator

@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
Collaborator

@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