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

Added async support #744

Merged
merged 1 commit into from
Feb 28, 2024
Merged

Added async support #744

merged 1 commit into from
Feb 28, 2024

Conversation

bvssvni
Copy link
Member

@bvssvni bvssvni commented Feb 28, 2024

See #741

Compiled behind Cargo feature: "async"

To compile the "dyonrun" example with async:

cargo build --release --features="async" --example dyonrun

Why async?

Dyon uses a Go-like model for concurrency. However, until now this used one OS thread per co-routine.
Since it is expensive to swap between threads in the OS, this becomes a bottleneck.

Async code in Rust makes it possible to execute thousands of tasks in parallel at much higher performance, using an executor runtime like Tokio.

Example

This example sums the first 10 000 natural numbers, creating a task for each number:

test.dyon

fn main() {
    xs := sift i 10_000 {go foo(i)}
    println(sum i len(xs) {
        x := pop(mut xs)
        unwrap(join(thread: x))
    })
}

fn foo(i: f64) -> bool {
    return clone(i)
}

On my laptop:
Without async (default): 3.15s user 1.82s system 118% cpu 4.185 total
With async: 0.06s user 0.02s system 155% cpu 0.057 total

@bvssvni bvssvni merged commit a13edb3 into PistonDevelopers:master Feb 28, 2024
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.

1 participant