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

Implement kani::spawn #1504

Closed
fzaiser opened this issue Aug 11, 2022 · 3 comments · Fixed by #1659
Closed

Implement kani::spawn #1504

fzaiser opened this issue Aug 11, 2022 · 3 comments · Fixed by #1659
Assignees

Comments

@fzaiser
Copy link
Contributor

fzaiser commented Aug 11, 2022

For asynchronous code, it's important to be able to spawn tasks. Since tokio::spawn or something similar will be difficult to support, we should provide our own version that is optimized for Kani. Part of #1393

@soareschen
Copy link

I tried to implement a basic async task scheduler similar to #1659. However I ran into performance issues that the non-deterministic execution of even just two simple async tasks are taking way too long time.

I identified the cause of the problem being from the dynamic dispatch of Future::poll() from a Pin<Box<dyn Future>>. I tried replacing the non-deterministic task scheduling with two hardcoded Pin<Box<impl Future>> tasks made of distinct opaque types. With that the solver gains at least 10x performance improvement, as compared to the same code that uses Pin<Box<dyn Future>>.

Does this have to do with the use of dynamic dispatch in dyn traits not working well with symbolic execution? If so, I'm not sure if we could implement general purpose async task spawners and schedulers in Kani without significant sacrifice on performance.

@tedinski
Copy link
Contributor

tedinski commented Nov 7, 2022

Could you try with --restrict-vtable? (This feature was never fully finished, but it helps a lot with dynamic dispatch, sometimes.)

@fzaiser
Copy link
Contributor Author

fzaiser commented Nov 7, 2022

@tedinski I just tried this option on manual_spawn.rs, and both with and without the flag, it took between 61 and 62s. If I understand correctly, --restrict-vtable, narrows the choice of pointer targets to those of a type that implements the trait (here Future). Since all spawned futures are dyn Future, --restrict-vtable does not help CBMC to narrow down the possible future types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Status: Done
Status: Done
Development

Successfully merging a pull request may close this issue.

5 participants