Skip to content

Conversation

@yc199911
Copy link
Contributor

Problem: pktbuf_is_complete() and pktbuf_pop_packet() use expensive memmove()
operations for packet alignment, causing O(n) performance overhead when
processing packets with garbage prefix data.

Changes:

  • Add 'start' field to pktbuf_t for window-based buffer management
  • Refactor pktbuf_is_complete() to use window offset instead of memmove
  • Refactor pktbuf_pop_packet() to use window offset instead of memmove
  • Change packet alignment from O(n) to O(1) time complexity

Future Considerations

This change lays groundwork for potential ring buffer implementation with readv() zero-copy I/O. Would appreciate maintainer feedback on this direction.

- Add 'start' field to pktbuf_t for window-based buffer management
- Refactor pktbuf_is_complete() to use window offset instead of memmove
- Refactor pktbuf_pop_packet() to use window offset instead of memmove
- Maintain full backward compatibility with identical test results
@yc199911 yc199911 force-pushed the feat/pktbuf-window-optimization branch from ebf9e24 to 1eef1ef Compare September 13, 2025 16:17
@RinHizakura
Copy link
Owner

RinHizakura commented Sep 23, 2025

Sure, using memmove() is not the best solution. But does this really work? When a packet is consumed, how can you recycle the buffer space? It seems like you just keep increasing the buffer to accept more incoming data.

If that's the case, the statement "Change packet alignment from O(n) to O(1) time complexity" actually means nothing, because it involves more memory allocation, which means paying extra cost in the global perspective for such "local optimization.

The ideal solution is to design a ring buffer for the packet buffer.

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