Skip to content

feat: implement window mechanism to eliminate memmove operations - #17

Open
yc199911 wants to merge 1 commit into
RinHizakura:mainfrom
yc199911:feat/pktbuf-window-optimization
Open

feat: implement window mechanism to eliminate memmove operations#17
yc199911 wants to merge 1 commit into
RinHizakura:mainfrom
yc199911:feat/pktbuf-window-optimization

Conversation

@yc199911

Copy link
Copy Markdown
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

RinHizakura commented Sep 23, 2025

Copy link
Copy Markdown
Owner

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.

@RinHizakura
RinHizakura force-pushed the main branch 2 times, most recently from b40c643 to dac98cc Compare March 5, 2026 15:44
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