pcapng: stop copying the unread option buffer for every option - #5103
Merged
Conversation
Each parsed option sliced the remaining unread metadata, so a capture with many small valid options made rdpcap() cost time quadratic in the option count. A 524,408-byte file with 65,536 comments took 251 ms to read while an equal-size file with eight comments took under one millisecond. Doubling the file took 1.24 s. Frames need not be large; these files hold one 34-byte Ethernet/IP frame and the rest is capture metadata. Walk the buffer by offset instead of reslicing it. A five-point growth run is classified linear after the change, and the valid-option benchmark went from 13,458.4 to 9,185.9 ns/call. AI-Assisted: yes (GPT-5.6-Cyber)
polybassa
approved these changes
Aug 25, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5103 +/- ##
==========================================
+ Coverage 79.42% 80.59% +1.16%
==========================================
Files 372 390 +18
Lines 96507 96858 +351
==========================================
+ Hits 76652 78059 +1407
+ Misses 19855 18799 -1056
🚀 New features to boost your workflow:
|
gpotter2
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each parsed pcapng option sliced the remaining unread metadata, so a capture holding many small
valid options made
rdpcap()cost time quadratic in the option count. The frames need not belarge — the files below hold one 34-byte Ethernet/IP frame and the rest is capture metadata.
A 524,408-byte file with 65,536 comments took 251 ms to read, while an equal-size file with eight
comments took under a millisecond. Doubling the file took 1.24 s.
This walks the buffer by offset instead of reslicing it. A five-point growth run is classified
linear after the change, and a valid-option benchmark went from 13,458.4 to 9,185.9 ns/call.
Test added in
test/regression.uts, using valid one-byte comments. It fails whenever the parsercopies a shrinking unread suffix.