Grow buffers exponentially, not one byte at a time #121
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.
To check if a TranscodingStream is eof, it first checks if it has any unused
bytes in its buffer. If not, it will attempt to fill the buffer, and only return
true if no bytes were filled.
If there is no margin in the buffer to fill, it will call
makemargin(buffer, 1)
to ensure at least 1 byte of space.
In the happy case, this will remove used up bytes.
Unfortunately, buffers do never move data pointed to by their mark. So, when no
space is available due to the entire buffer being filled up with marked data,
the buffer will grow one byte at a time in a loop until the data fills.
This is unacceptable as megabytes of data can theoretically be marked.
This commit changes the growth behaviour to request at least half the buffer's
length in the margin. In most cases, this will do nothing. But in the unhappy
case mentioned above, it will cause the buffer to grow expoentially, until a
proper size is quickly reached.