Skip to content

Commit 7fe9141

Browse files
committed
Eagerly clear buffer when past a certain size
1 parent e79e9e5 commit 7fe9141

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/redis_client/ruby_connection/buffered_io.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ def fill_buffer(strict, size = @chunk_size)
193193
start = @offset - @buffer.bytesize
194194
empty_buffer = start >= 0
195195

196+
if !empty_buffer && @offset > (@chunk_size * 2)
197+
old_buffer = @buffer
198+
@buffer = @buffer.byteslice(@offset..-1)
199+
old_buffer.clear
200+
@offset = 0
201+
start = @offset - @buffer.bytesize
202+
end
203+
196204
loop do
197205
bytes = if empty_buffer
198206
@io.read_nonblock([remaining, @chunk_size].max, @buffer, exception: false)

0 commit comments

Comments
 (0)