Skip to content

Commit

Permalink
Eagerly clear buffer when past a certain size
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Apr 16, 2024
1 parent 336ce1c commit a839583
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/redis_client/ruby_connection/buffered_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ def fill_buffer(strict, size = @chunk_size)
start = @offset - buffer_size
empty_buffer = start >= 0

if !empty_buffer && @offset > (@chunk_size * 2)
old_buffer = @buffer
@buffer = @buffer.byteslice(@offset..-1)
old_buffer.clear
@offset = 0
start = @offset - @buffer.bytesize
end

loop do
bytes = if empty_buffer
@io.read_nonblock([remaining, @chunk_size].max, @buffer, exception: false)
Expand Down

0 comments on commit a839583

Please sign in to comment.