From 643e534053cd13655ed2ee0bda6b3b5cd15e5f16 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 17 Jan 2025 21:41:02 +0530 Subject: [PATCH] Do not call monotonic() when changing cursor position monotonic() is extremely slow. This call was halving the CSI parsing speed benchmark. Instead we use the time at which parsing of the current input chunk was started. This should be within a few microseconds and accurate enough for the cursor trail for which it is used. --- kitty/screen.c | 2 +- kitty/screen.h | 1 + kitty/vt-parser.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kitty/screen.c b/kitty/screen.c index 784791fe79..202f3e9a06 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1805,7 +1805,7 @@ screen_cursor_position(Screen *self, unsigned int line, unsigned int column) { line += self->margin_top; line = MAX(self->margin_top, MIN(line, self->margin_bottom)); } - self->cursor->position_changed_by_client_at = monotonic(); + self->cursor->position_changed_by_client_at = self->parsing_at; self->cursor->x = column; self->cursor->y = line; screen_ensure_bounds(self, false, in_margins); } diff --git a/kitty/screen.h b/kitty/screen.h index ff3db26b5e..e93eba7b07 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -173,6 +173,7 @@ typedef struct { } paused_rendering; CharsetState charset; ListOfChars *lc; + monotonic_t parsing_at; } Screen; diff --git a/kitty/vt-parser.c b/kitty/vt-parser.c index 78bc86470f..df789d1b04 100644 --- a/kitty/vt-parser.c +++ b/kitty/vt-parser.c @@ -1417,6 +1417,7 @@ static void run_worker(void *p, ParseData *pd, bool flush) { Screen *screen = (Screen*)p; PS *self = (PS*)screen->vt_parser->state; + screen->parsing_at = pd->now; with_lock { self->read.sz += self->write.pending; self->write.pending = 0; pd->has_pending_input = self->read.pos < self->read.sz;