From c75d7f60cb3334817ae5017d4ee4064319e132f3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 Dec 2016 16:56:26 +0530 Subject: [PATCH] Speed up draining of the wakeup_fd buffer --- kitty/data-types.c | 9 +++++++++ kitty/tabs.py | 7 ++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/kitty/data-types.c b/kitty/data-types.c index 872683226..fe8977e15 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -10,8 +10,17 @@ #include "gl.h" #include "modes.h" +static char drain_buf[1024] = {0}; + +static PyObject* +drain_read(PyObject UNUSED *self, PyObject *fd) { + read(PyLong_AsLong(fd), drain_buf, sizeof(drain_buf)); + Py_RETURN_NONE; +} + static PyMethodDef module_methods[] = { GL_METHODS + {"drain_read", (PyCFunction)drain_read, METH_O, ""}, {"parse_bytes", (PyCFunction)parse_bytes, METH_VARARGS, ""}, {"parse_bytes_dump", (PyCFunction)parse_bytes_dump, METH_VARARGS, ""}, {"read_bytes", (PyCFunction)read_bytes, METH_VARARGS, ""}, diff --git a/kitty/tabs.py b/kitty/tabs.py index 6fec2f69f..283f8c429 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -22,7 +22,7 @@ from .constants import ( from .fast_data_types import ( glViewport, glBlendFunc, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GLFW_PRESS, GLFW_REPEAT, GLFW_MOUSE_BUTTON_1, glfw_post_empty_event, - GLFW_CURSOR_NORMAL, GLFW_CURSOR, GLFW_CURSOR_HIDDEN, + GLFW_CURSOR_NORMAL, GLFW_CURSOR, GLFW_CURSOR_HIDDEN, drain_read ) from .fonts import set_font_family from .borders import Borders, BordersProgram @@ -199,10 +199,7 @@ class TabManager(Thread): def on_wakeup(self): if not self.shutting_down: - try: - os.read(self.read_wakeup_fd, io.DEFAULT_BUFFER_SIZE) - except (EnvironmentError, BlockingIOError): - pass + drain_read(self.read_wakeup_fd) while True: try: func, args = self.action_queue.get_nowait()