-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Align output to buffer size in rcfile writer #9001
Conversation
9cf1768
to
ab2c3e3
Compare
length -= flushLength; | ||
} | ||
|
||
// line up the chuck to buffer size and flush directly to OutputStream |
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.
Typo
a188bec
to
887e3a9
Compare
|
||
// line up the chunk to chunk size and flush directly to OutputStream | ||
int flushLength = length - length % CHUNK_SIZE; | ||
for (int i = 0; i < flushLength / CHUNK_SIZE; i++) { |
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 think it would be simpler to do:
while (length <= CHUNK_SIZE) {
writeToOutputStream(source, sourceIndex, CHUNK_SIZE);
sourceIndex += CHUNK_SIZE;
length -= CHUNK_SIZE;
}
then after the loop you don't need to touch length of bufferOffset.
} | ||
|
||
// line up the chunk to chunk size and flush directly to OutputStream | ||
int flushLength = length - length % CHUNK_SIZE; |
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.
same here
// test some different buffer sizes | ||
for (int bufferSize : new int[] {4096, 4345, 65535, 65536, 65537, 100000}) { | ||
// check byte array version | ||
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(length); |
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.
Make a subclass that captures the flush sizes and then validate you don't get flushes > 4k
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.
One comment, but otherwise looks good
} | ||
|
||
// buffer the remaining data |
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.
wrapper this with if (length != 0)
} | ||
|
||
// buffer the remaining data |
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.
same
Flushing data in arbitrary sizes can be a problem for memory fragmentation. This is generally fine unless the output stream can allocate native memory (e.g., gzip streams). Native memory allocator may not be able to compact fragmentation, which can cause native memory OOM.
Flushing data in arbitrary sizes can be a problem for memory
fragmentation. This is generally fine unless the output stream can
allocate native memory (e.g., gzip streams). Native memory allocator may
not be able to compact fragmentation, which can cause native memory OOM.
Resolves #8993