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.
This commit is contained in:
Kovid Goyal
2025-01-17 21:41:02 +05:30
parent 9bf44f0b85
commit 643e534053
3 changed files with 3 additions and 1 deletions

View File

@@ -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);
}

View File

@@ -173,6 +173,7 @@ typedef struct {
} paused_rendering;
CharsetState charset;
ListOfChars *lc;
monotonic_t parsing_at;
} Screen;

View File

@@ -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;