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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[pkg/stanza] Introduce batching logs in File consumer #36663
base: main
Are you sure you want to change the base?
[pkg/stanza] Introduce batching logs in File consumer #36663
Changes from 6 commits
6b4c9fe
c206995
aedda3a
477f67b
13d6054
dda1a60
961789e
07e0465
f650804
de66483
d8704ab
5734fcc
1af6281
f6b44e0
4696c39
6d4dc42
64a5098
6bf73cc
b67c222
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What specifically introduces a need to make copies of the body and attributes?
It seems like a lot of overhead - are we sure it's necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without copying, for each token in the
tokens
collection, its Body would point to the same place in memory, specifically the Decoder's decodeBuffer.This isn't a problem when the Reader emits each token before creating a new token, as the token's Body is copied in the
emit
function (specifically in the toBody function - the conversion from[]byte
tostring
copies the underlying array).Similar with the attributes, the
reader::FileAttributes
map would be reused by all tokens if not copied.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding correctly then, we're just making the copies in a different place, so this does not introduce new work into the hot path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid it does introduce new work.
How I believe this worked before this change:
emit
functionemit
function reads the bytes and creates a newEntry
, copying the bytes into a new area in memory.How this works after this change:
readContent
function, a batch of tokens is accumulated before calling theemit
function, so the bytes fromdecodeBuffer
need to be copied into a new area in memory for every new tokenemit
function, which creates a new Entry for every Token, copying the bytes for the second time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is in the hot path, we might be better off flattening these functions. It seems like a lot of extra error checking and wrapping, where we really just need to put a loop around what was already there, switch from return to append err + continue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have inlined the
convertToken
function in de66483. Should I inline theconvertTokens
function as well?