Skip to content

Conversation

@PSUdaemon
Copy link
Contributor

@PSUdaemon PSUdaemon commented Dec 11, 2025

@PSUdaemon PSUdaemon requested a review from a team as a code owner December 11, 2025 17:55
Comment on lines 149 to 153
impl PartialOrd for Estimate {
#[allow(clippy::non_canonical_partial_ord_impl)]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.bandwidth.partial_cmp(&other.bandwidth)
Some(self.cmp(other))
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the Ord implementation:

impl Ord for Estimate {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.bandwidth.cmp(&other.bandwidth)
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@antoniovicente please check

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems correct. loss is ignored consistently for eq and cmp.

// Priority ordering is complex, disable Clippy warning.
#[allow(clippy::non_canonical_partial_ord_impl)]
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
Some(self.cmp(other))
Copy link
Contributor

Choose a reason for hiding this comment

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

Touching this always makes me a little nervous but we have test coverage and that seems to have passed

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the before and after do the same, even if the semantics of the comparison are surprising.

// Ignore priority if ID matches.
if self.id == other.id {
return Some(cmp::Ordering::Equal);
return cmp::Ordering::Equal;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm worried about correctness due to this line.

Ignoring the other fields if the ids are equal seems very very bad as it doesn't allow for correct sorting for a collection of elements when there are 2 with same id but differences in other fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

Its kinda implicit in the overall design but where StreamPriorityKey would be used, there cannot be two objects with the same stream ID (If there were, we'd have bigger issues 😂 )

fn cmp(&self, other: &Self) -> cmp::Ordering {
// `partial_cmp()` never returns `None`, so this should be safe.
self.partial_cmp(other).unwrap()
cmp::Ordering::Greater
Copy link
Contributor

@antoniovicente antoniovicente Dec 12, 2025

Choose a reason for hiding this comment

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

I don't know what the requirements for cmp are and what are the consequences of having elements that return different answers if you swap the argument order.

I think this is a case where the id could be compared.

In the partial order case, this case may want to return None.

Copy link
Contributor

Choose a reason for hiding this comment

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

That would break the prioritization algorithm which needs these types of streams to be round-robined. This is a bit of a trick, newly added incremental streams of the same urgency to "go to the back", so by removing then adding a stream when it's been visited (e.g. to send data) we can ensure the next visit hits the next stream of this type.

Copy link
Contributor

@antoniovicente antoniovicente left a comment

Choose a reason for hiding this comment

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

Seems like an improvement. Thanks for the lint fixes.

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.

3 participants