forked from grpc/grpc-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discard excess read bytes in LengthPrefixedMessageReader. (grpc#781)
It is possible, in some use-cases, for LengthPrefixedMessageReader to build up a buffer with loads of "free" space at the front that is not usable, but that cannot be freed due to incoming messages arriving sufficiently quickly. We should, from time to time, try to discard those messages by compacting the buffer. It's hard to have a good heuristic here, so this patch represents a first-pass: if there's more than 1kB of usable space in the buffer that we could free up with compaction, and if that space is larger than the usable bytes in the buffer, we should try to obtain it. This effectively doubles the size of the buffer "for free", which is what a resizing would do anyway. It also makes a subsequent resizing cheaper, as we no longer need to copy the leading bytes to preserve the reader index.
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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