Skip to content

Better memory footprint #137

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

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

purplesyringa
Copy link
Contributor

By creating the future manually instead of relying on async { .. }, we workaround rustc's inefficient future layouting. On a simple benchmark spawning 1M of tasks, this reduces memory use from about 512 bytes per future to about 340 bytes per future.

More context: hez2010/async-runtimes-benchmarks-2024#1

This PR is rebased onto #136 because tests fail otherwise; please consider that PR first. On this PR, the relevant part for review is the second commit.

@purplesyringa
Copy link
Contributor Author

Note that this also fixes a leak, at least theoretically. Before this PR, the Waker would not be freed if the future was immediately dropped without ever being polled. I'm not sure how realistic that is, but IMO the new code is more intuitively correct.

Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

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

LGTM, will merge once rebased on master.

@@ -23,6 +23,7 @@ async-task = "4.4.0"
concurrent-queue = "2.5.0"
fastrand = "2.0.0"
futures-lite = { version = "2.0.0", default-features = false }
pin-project-lite = "0.2"
Copy link
Member

Choose a reason for hiding this comment

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

Noting to myself that this is not a new dependency, since futures-lite imports it already.

By creating the future manually instead of relying on `async { .. }`, we
workaround rustc's inefficient future layouting. On
[a simple benchmark](https://github.com/hez2010/async-runtimes-benchmarks-2024)
spawning 1M of tasks, this reduces memory use from about 512 bytes per
future to about 340 bytes per future.

More context: hez2010/async-runtimes-benchmarks-2024#1
@purplesyringa purplesyringa force-pushed the better-memory-footprint branch from 4ef4564 to 09ed703 Compare December 3, 2024 08:26
@purplesyringa
Copy link
Contributor Author

Rebased.

@notgull notgull merged commit 47739f1 into smol-rs:master Dec 3, 2024
8 checks passed
@purplesyringa
Copy link
Contributor Author

Thank you!

@taiki-e taiki-e mentioned this pull request Apr 28, 2025
@taiki-e
Copy link
Collaborator

taiki-e commented Apr 28, 2025

Published in 1.13.2.

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

Successfully merging this pull request may close these issues.

3 participants