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 a new algorithm to make this crate no_std #30

Closed
wants to merge 11 commits into from
Closed

Conversation

notgull
Copy link
Member

@notgull notgull commented Sep 5, 2022

This PR resolves #28 by replacing this crate's algorithm with one that is compatible with no_std. I realized that the current algorithm is basically a concurrent queue, so I replaced it with our concurrent_queue crate. The underlying implementation is basically the same, but there is a new std feature that prevents parking primitives from being used. This is a breaking change, since removing the std feature removes the wait_* family of functions.

For now, this is a draft PR because:

  • I'm waiting for the changes I made to concurrent_queue to be released; right now I'm just using master the branch where I'm implementing Loom support.
  • The new implementation pasts the existing tests, but I'd like to check to see if it also passes the tests for async-channel and async-lock when it is patched in. Test suites pass when I patch in this new version of event-listener.
  • There's a merge conflict I don't feel like resolving right now. Should be fixed by now.
  • I'd like to benchmark the changes before I merge them. The new algorithm may allocate more often than the older algorithm. Although this allocation will likely be amortized over the program's runtime, I'd like to be sure that it doesn't impact performance significantly. See Add basic benchmarks #31. See my comment below.
  • I also implemented partial support for loom testing, but I haven't gotten around to writing the tests for that yet.

Future considerations:

  • Since ConcurrentQueue::bounded() is more efficient than ConcurrentQueue::unbounded(), it may be useful to provide a "with maximum length" method that allocates everything up front.

@notgull
Copy link
Member Author

notgull commented Sep 9, 2022

Now that I can test the benchmarks, it seems that it's regressed to an almost unacceptable degree.

benching

I'm not entirely sure where the extra overhead is coming from, I'll start looking into it.

Also, I can't reproduce that MIRI failure on my machine. I guess it's time to try out Loom.

@taiki-e
Copy link
Collaborator

taiki-e commented Sep 9, 2022

Seems Miri failure is due to detached threads in doctest: rust-lang/miri#1371

A workaround that I sometimes use is adding sleep to the end of test: crossbeam-rs/crossbeam#891

@notgull
Copy link
Member Author

notgull commented Oct 3, 2022

With the newest commit, I have it down to only 30% slower.


use loom::sync::{Arc, Condvar, Mutex};

/// Re-implementation of `parking::pair` based on loom.
Copy link
Member

Choose a reason for hiding this comment

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

Can we upstream this into https://github.com/smol-rs/parking ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! It should be a straightforward reimplementation in terms of Loom primitives.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, it's smol-rs/parking#8

Copy link
Member

Choose a reason for hiding this comment

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

now that it's upstreamed, can we use that version? (although I don't know how it would interact with dependencies...) Does cargo correctly work with git deps which also have versions (e.g. transforms them into crates.io entries on publishing)?

src/lib.rs Show resolved Hide resolved
@notgull
Copy link
Member Author

notgull commented Nov 1, 2022

Closing in favor of #33

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.

Make this crate no_std
3 participants