Skip to content

Conversation

@Searchstars
Copy link
Contributor

Changed the vector size used to construct the packet buffer from u16::MAX as usize + offset to mtu + offset, reducing unnecessary memory allocations (especially on memory-constrained microcontroller devices).

@Searchstars Searchstars changed the title Optimize memory allocation logic when building packet buffer Optimize memory allocation logic when constructing packet buffer Nov 12, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes memory allocation for packet buffer construction in resource-constrained environments (especially microcontrollers running ESP-IDF). The change reduces the buffer size from u16::MAX + offset (≈65KB) to mtu + offset, using the MTU configuration value with a minimum of 1280 bytes.

  • Replaces hardcoded u16::MAX buffer size with MTU-based allocation
  • Adds MIN_IP_PACKET_LEN constant (1280 bytes) per RFC 8200 for IPv6
  • Extends target OS support to include ESP-IDF

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Searchstars
Copy link
Contributor Author

The reviewer’s comments have been addressed. The primary update changes the default MTU from u16::MAX to the RFC-defined theoretical minimum to reduce unnecessary memory usage, while still allowing users to specify a larger MTU if required.

@ssrlive ssrlive merged commit a97609c into narrowlink:main Nov 17, 2025
2 checks passed
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