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

feat: Rework the internal structure of the event-listener crate #51

Merged
merged 21 commits into from
Apr 2, 2023

Conversation

notgull
Copy link
Member

@notgull notgull commented Mar 16, 2023

Alright, here we go again.

This PR once again reworks the internal structure of event-listener. An intrusive linked list is the fastest way to handle an event queue, but isn't available in libstd. Therefore, this PR reworks the internals such that the implementation of event handling used depends on whether or not the libstd feature is enabled:

  • If std is enabled, then it uses the intrusive linked list.
  • If std isn't enabled, then it falls back to the current master strategy of using a linked list arena falling back to an atomic queue.

I'm pretty happy with this iteration at this stage. Draft because I still need to refine the tests.

@notgull notgull marked this pull request as ready for review March 17, 2023 19:02
@notgull notgull requested a review from fogti March 29, 2023 16:21
benches/bench.rs Outdated Show resolved Hide resolved
@fogti
Copy link
Member

fogti commented Mar 29, 2023

ok, so some changes do affect lifetimes and sprinkle as_mut() all over the place, can we split them out as much as possible (perhaps even do them without changing any functionaliy, e.g. via PhantomData for lifetimes, so that the noise is reduced)? Reviewing this in the current state is really hard, as it is not clear what is moved and how.

@@ -188,7 +188,7 @@ impl Inner {
match next {
None => self.tail = prev,
Some(n) => unsafe {
n.as_ref().next.set(prev);
n.as_ref().prev.set(prev);
Copy link
Member

Choose a reason for hiding this comment

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

what happens here?

Copy link
Member Author

Choose a reason for hiding this comment

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

There was a bug in there that was causing the MIRI issues. It should be fixed now.

@fogti
Copy link
Member

fogti commented Mar 29, 2023

  • The commit fmt should be squashed with the commit which introduced the formatting divergence (that is, modified that code segment previously).
  • The commit Wait tests are hanging on MIRI, not sure why which seems to affect the first commit should also be squashed into it.
  • The second commit Build ndf into C/I appears ok, but the commit message should be refined to explain it better.
  • The first commit Incomplete should then be split into several, optimally independent commits which should compile on their own and demonstrate what code is moved. This branch should not be squashed upon merging, as the structure and hopefully step-wise natrue of the resulting commits is by then probably necessary to understand what is going on.
  • The last commit might be further refined, but also appears currently ok

This move abstracts them to be a sub-module of the inner list.
Ideally, we should have as few dependencies as possible. This change
inlines most of the logic from `slab` that we used into the
`ListenerSlab` struct.
Everything from that crate can either be inlined or ignored.

I also fix a bug with the list implementation as well.
- Renames "list.rs" and the "list" folder to "no_std"
- Uses `no_std` as the `sys` module in preparation for the `std` module
- Inlines `sync.rs` into `lib.rs`
First part of EventListener reworks. The idea here is that, in the
future, we can add an "EventListenerRef" structure that just takes
an "&'a Inner" rather than an "Arc<Inner>". This way, you don't
need to do an atomic clone for listening.
This optimization is inspired by what futures_lite does for the block_on
function. This should prevent users from dealing with the overhead of
creating a parker and unparker every time wait() is called.
The EventListener for the upcoming libstd-based implementation needs to
be pinned, so this commit sets up the infrastructure for the pinned
EventListener.

This is a breaking change.
This implementation is around 20% faster than the no_std one, according
to benchmarks. Therefore, we should use it where we can.
- Adds the unit test set to the no_std implementation
- Fixes doc tests in event-listener-strategy
@notgull
Copy link
Member Author

notgull commented Mar 31, 2023

I've split the Incomplete commit into about 15 sub-commits, so this should be easier to review incrementally now.

src/lib.rs Outdated Show resolved Hide resolved
src/list.rs Outdated Show resolved Hide resolved
src/list.rs Outdated Show resolved Hide resolved
src/list.rs Outdated Show resolved Hide resolved
src/list.rs Outdated Show resolved Hide resolved
src/list.rs Outdated Show resolved Hide resolved
src/std.rs Outdated Show resolved Hide resolved
@fogti
Copy link
Member

fogti commented Apr 2, 2023

thanks, looks overall LGTM.

@fogti fogti merged commit a9595d3 into master Apr 2, 2023
@fogti fogti deleted the notgull/rework-int-list branch April 2, 2023 19:09
@notgull notgull mentioned this pull request May 20, 2023
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.

2 participants