netlink: add parseMessagesIter to reduce memory usage#266
Merged
nickgarlis merged 1 commit intomdlayher:mainfrom Mar 12, 2026
Merged
netlink: add parseMessagesIter to reduce memory usage#266nickgarlis merged 1 commit intomdlayher:mainfrom
nickgarlis merged 1 commit intomdlayher:mainfrom
Conversation
nickgarlis
commented
Mar 9, 2026
| // Each iteration yields a Message and any error encountered during parsing. | ||
| // The iterator stops on the first error or when all messages are parsed. | ||
| // | ||
| // If b is less that NLMSG_HDRLEN bytes, no error or messages will be returned. |
Collaborator
Author
There was a problem hiding this comment.
This is to keep the behavior similar to syscall.ParseNetlinkMessage
Collaborator
Author
|
cc @aojea in case you're interested |
6b8fc8c to
b365d7a
Compare
Introduce a parseMessages iterator to improve parsing performance and serve as the foundation for a future receive iterator in the public API. The functionality in syscall.ParseNetlinkMessage is very similar to to Message.UnmarshalFromBinary; the only missing part was walking the buffer, which has now been implemented in this iterator. Synthetic benchmarks show a performance improvement when parsing and collecting messages using this approach.
b365d7a to
3dad657
Compare
Collaborator
Author
|
BenchmarkNftablesDump shows about a 1.8% reduction in memory and a small drop in allocations. Nothing huge, but the larger improvements will come in the next change. |
thanks for doing this |
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.
Introduce a parseMessages iterator to improve parsing performance and serve as the foundation for a future receive iterator in the public API.
The functionality in syscall.ParseNetlinkMessage is very similar to to Message.UnmarshalFromBinary; the only missing part was walking the buffer, which has now been implemented in this iterator.
Synthetic benchmarks show a performance improvement when parsing and collecting messages using this approach.
In more detail, the benchmark compared the old approach (syscall.ParseNetlinkMessage + conversion) with the new
iterator approach (parseMessagesIter + collection into slice).