Skip to content

Commit 4f66353

Browse files
author
taras
committed
Skip fast path in _initiate_write() if we attempted it in write(). This removes unnecessary syscall
1 parent 94cbc7f commit 4f66353

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

uvloop/handles/stream.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cdef class UVStream(UVBaseTransport):
3535
# and then call _initiate_write() to start writing either immediately or in
3636
# the next iteration (loop._queue_write()).
3737
cdef inline _buffer_write(self, object data)
38-
cdef inline _initiate_write(self)
38+
cdef inline _initiate_write(self, bint skip_fast_path)
3939

4040
# _exec_write() is the method that does the actual send, and _try_write()
4141
# is a fast-path used in _exec_write() to send a single chunk.

uvloop/handles/stream.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,13 @@ cdef class UVStream(UVBaseTransport):
424424
self._buffer_size += dlen
425425
self._buffer.append(data)
426426

427-
cdef inline _initiate_write(self):
428-
if (not self._protocol_paused and
429-
(<uv.uv_stream_t*>self._handle).write_queue_size == 0 and
430-
self._buffer_size > self._high_water):
427+
cdef inline _initiate_write(self, bint skip_fast_path):
428+
if (not skip_fast_path and
429+
not self._protocol_paused and
430+
(<uv.uv_stream_t*>self._handle).write_queue_size == 0 and
431+
self._buffer_size > self._high_water):
431432
# Fast-path. If:
433+
# - the caller hasn't tried fast path itself
432434
# - the protocol isn't yet paused,
433435
# - there is no data in libuv buffers for this stream,
434436
# - the protocol will be paused if we continue to buffer data
@@ -687,9 +689,7 @@ cdef class UVStream(UVBaseTransport):
687689

688690
cdef ssize_t bytes_written
689691

690-
if (not self._protocol_paused and self._buffer_size == 0 and
691-
(<uv.uv_stream_t*>self._handle).write_queue_size == 0):
692-
692+
if self._get_write_buffer_size() == 0:
693693
bytes_written_ = self._try_write(buf)
694694

695695
if bytes_written_ is None:
@@ -726,7 +726,7 @@ cdef class UVStream(UVBaseTransport):
726726
# buffer remaining data and send it later
727727

728728
self._buffer_write(buf)
729-
self._initiate_write()
729+
self._initiate_write(True) # skip fast path in _initiate_write
730730

731731
def writelines(self, bufs):
732732
self._ensure_alive()
@@ -738,7 +738,7 @@ cdef class UVStream(UVBaseTransport):
738738
return
739739
for buf in bufs:
740740
self._buffer_write(buf)
741-
self._initiate_write()
741+
self._initiate_write(False) # try fast path in _initiate_write
742742

743743
def write_eof(self):
744744
self._ensure_alive()

0 commit comments

Comments
 (0)