Skip to content

perf: reduce allocations and optimize hot paths in network simulation#89

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/improve-slow-code-efficiency
Draft

perf: reduce allocations and optimize hot paths in network simulation#89
Copilot wants to merge 3 commits intomainfrom
copilot/improve-slow-code-efficiency

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 29, 2025

Identified and fixed several allocation and algorithmic inefficiencies in network packet handling and collection management.

Changes

  • Packet segmentation (ip/segments.rs): Eliminated clone on final segment by using Option<Packet> ownership model
  • Address hashing (queue/sender.rs): Sized arrays exactly to address type (6 bytes IPv4, 18 bytes IPv6) instead of always allocating 18
  • Collection removal (queue/sender.rs): Replaced VecDeque::retain() with position() + remove() for targeted element deletion
  • Bitset queries (time/bitset.rs): Changed is_empty() from fold to all() for early-return optimization
  • Vector pre-allocation (task/supervisor.rs, pcap/*.rs): Added with_capacity() where size is known upfront

Example: Segment Iterator

Before:

let mut packet = self.packet.clone();  // Clone on every segment
*packet.transport.payload_mut() = payload;

After:

// Take ownership on last segment, clone only intermediate ones
let mut packet = if is_last {
    self.packet.take()?
} else {
    packet.clone()
};
Original prompt

Identify and suggest improvements to slow or inefficient code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 29, 2025 01:32
Co-authored-by: camshaft <799311+camshaft@users.noreply.github.com>
Co-authored-by: camshaft <799311+camshaft@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements to slow code perf: reduce allocations and optimize hot paths in network simulation Oct 29, 2025
Copilot AI requested a review from camshaft October 29, 2025 01:40
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.

2 participants