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

Make gathering of dropped packets more efficient #182

Open
1 task
jstnlef opened this issue Apr 30, 2019 · 5 comments
Open
1 task

Make gathering of dropped packets more efficient #182

jstnlef opened this issue Apr 30, 2019 · 5 comments
Labels
difficulty: easy enhancement New feature or request good first issue Good for newcomers

Comments

@jstnlef
Copy link
Contributor

jstnlef commented Apr 30, 2019

Task Description

Over here we allocate a new vector for dropped packets. In a perfect scenario, this should be avoided.

Task TODO

There is likely a way to set this up to just return a lazy iterator to prevent the vector allocation. It's worth exploring.

  • Investigate into different options to remove this allocation
@TimonPost
Copy link
Owner

Research if the following is possible: we could return a lazy loader here, instead of collecting, and do the same over here and then continue this lazy operator here.

@kstrafe
Copy link
Contributor

kstrafe commented Jun 17, 2019

Tried this with an impl Iterator but the problem is that we drain the sent_packets structure while at the same time iterating over its keys.

The workaround is to collect the keys into a Vec<u16>, but that's an unnecessary allocation. I think std should have a drain_if method.

@TimonPost TimonPost changed the title gather_dropped_packets could be done more efficiently Make gathering of dropped packets more efficient Jul 6, 2019
@TimonPost TimonPost added difficulty: easy enhancement New feature or request good first issue Good for newcomers labels Jul 6, 2019
@ncallaway
Copy link
Contributor

@jstnlef It looks like this has been refactored since this issue was created, so that link is no longer good. Any chance you can find and link to the new place where we're now unnecessarily allocating the Vec?

@chocolacula
Copy link

@BourgondAries:

Tried this with an impl Iterator but the problem is that we drain the sent_packets structure while at the same time iterating over its keys.

The workaround is to collect the keys into a Vec<u16>, but that's an unnecessary allocation. I think std should have a drain_if method.

It has drain_filter in nightly-only. Without it as an option we can use something like:

pub fn dropped_packets(&mut self) -> Vec<SentPacket> {
        let mut sent_sequences: Vec<SentPacket> = Vec::new();

        let remote_ack_sequence = self.remote_ack_sequence_num;
        self.sent_packets.retain(|key, value| {
            if sequence_less_than(*key, remote_ack_sequence)
                && remote_ack_sequence.wrapping_sub(*key) > REDUNDANT_PACKET_ACKS_SIZE
            {
                sent_sequences.push(value.clone());
                false
            } else {
                true
            }
        });

        sent_sequences
    }

But it still leads to necessary using clone() for each retaining value although without allocation of the vector with keys. If it is an appropriate solution while Rust API is stabilizing and merging into new release I can create PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants