From: Ben Darnell Date: Wed, 6 Jul 2011 05:34:26 +0000 (-0700) Subject: Add a fast path for IOStream writes in addition to reads. X-Git-Tag: v2.1.0~107 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=894fa93e88fd4075711fc69db29f5df7b2b39228;p=thirdparty%2Ftornado.git Add a fast path for IOStream writes in addition to reads. This is a significant speedup for small requests, since it is now possible to do a request and (synchronous) response without calling IOLoop.add_handler. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index 8a328eca2..b41800f10 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -174,8 +174,15 @@ class IOStream(object): assert isinstance(data, bytes_type) self._check_closed() self._write_buffer.append(data) - self._add_io_state(self.io_loop.WRITE) self._write_callback = stack_context.wrap(callback) + self._handle_write() + if self._write_buffer: + self._add_io_state(self.io_loop.WRITE) + elif callback is None and self._state is None: + # if callback is not None and we just completed the write + # in the fast path, _add_io_state will be called from + # _run_callback (see comments there for why) + self._add_io_state(0) def set_close_callback(self, callback): """Call the given callback when the stream is closed."""