-
-
Notifications
You must be signed in to change notification settings - Fork 400
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
Make quinn_proto::Connection
and quinn_proto::Endpoint
impl Sync
#1769
Conversation
I'm strongly in favor of getting rid of the
|
When implementing this originally, I was fond of the idea of using the
This would increase the number of layers of indirection to 3, needing to go through
In the common case of only having a few or even just 1 priority in use, this only has 2 layers of indirection, although this would increase with more priorities as the I think that the latter alternative is better, as making the code simpler and more understandable would be very valuable, and it's not clear that it would even have a meaningful impact on performance - I know that I had some trouble understanding the original implementation because of the tricky bookkeeping for always keeping at least 1 empty |
Yeah, I'm not happy with the existing code either. Proceeding with the |
So, I've decided to keep the current approach of removing the Edit: I thought about this some more, and I think this time round, it actually is much simpler than before, as this removes all of the aforementioned complexity working around
I don't think the idea of the recency value is actually any more complex that rotating a |
So, CI is failing because of the use of the |
I think bumping to 1.66 is probably fine at this point -- please either squash your other commits and add a separate commit for this or do this in a separate PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this generally looks good. It would be nice to squash this into 3 commits:
- MSRV bump
- Changes for the new priority management
- Other changes that add
Send + Sync
bounds
I went ahead and opened #1810 for the MSRV bump, since I was excited to get rid of some janky old |
The main goal of this refactor is to remove a `RefCell` that is preventing `Connection` from being `Sync`. This is achieved by replacing the `BinaryHeap` with a `BTreeMap`. See quinn-rs#1769 for more information.
Rebased ontop of #1810 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like this was rebased correctly? The commits from #1810 should not longer appear in this PR since they have been merged into main already, and there's a conflict left.
Otherwise, your new commits look good to me, thanks!
The main goal of this refactor is to remove a `RefCell` that is preventing `Connection` from being `Sync`. This is achieved by replacing the `BinaryHeap` with a `BTreeMap`. See quinn-rs#1769 for more information.
It looks like #1810 was updated inbetween me rebasing onto it and it getting merged into main. Should be fixed now. |
Great -- will leave it to @Ralith to have another look before merging, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a great simplification!
Can you squash the new simplification commit into the first commit? |
The main goal of this refactor is to remove a `RefCell` that is preventing `Connection` from being `Sync`. This is achieved by replacing it with a monotonically decreasing 'recency' counter. See quinn-rs#1769 for more information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'm really happy with how this has turned out! Simultaneously cleaner, more efficient, and presenting a better API 🎉
The main goal of this refactor is to remove a `RefCell` that is preventing `Connection` from being `Sync`. This is achieved by replacing it with a monotonically decreasing 'recency' counter. See quinn-rs#1769 for more information.
The main goal of this refactor is to remove a `RefCell` that is preventing `Connection` from being `Sync`. This is achieved by replacing it with a monotonically decreasing 'recency' counter. See #1769 for more information.
The only things preventing these types from already being
Sync
were a lack ofSync
bounds on trait objects they were storing, and aRefCell
that was only being used to work around a limitation in the API ofBinaryHeap
.Adding
Sync
bounds to the relevant traits was simple enough and didn't cause any warnings or errors, but to remove theRefCell
it was necessary to rework the way that pending stream IDs were stored.The specific motivation for this PR was so that I could store these types as components directly in the Bevy ECS, which requires component types be
Send + Sync
for multi-threaded system scheduling. The alternative would be to wrap the types in aMutex
or other synchronization primitive, but removing the limitation entirely seemed like the better option, given how the only non-trivial blocker was just a hacky workaround an API limitation.The aforementioned rework to remove the
RefCell
also (IMO) simplifies the logic a fair bit, by utilizing theBinaryHeap
's sorting for both priority and fairness. Sorting for stream IDs with the same priority falls back to arecency
counter, which is decremented each time that stream is processed. This causes the streams of the same priority to be 'cycled' through, in the same way that was achieved previously by popping from the front and pushing to the back of aVecDeque
that has now been removed. Technically the u64 could underflow and break the cycling, but that is highly unlikely to ever happen, due to the counter being initialized tou64::MAX
and only being decremented by 1 at a time.