Skip to content

Commit

Permalink
Do not call monotonic() when changing cursor position
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kovidgoyal committed Jan 17, 2025
1 parent 9bf44f0 commit 643e534
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kitty/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions kitty/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ typedef struct {
} paused_rendering;
CharsetState charset;
ListOfChars *lc;
monotonic_t parsing_at;
} Screen;


Expand Down
1 change: 1 addition & 0 deletions kitty/vt-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 643e534

Please sign in to comment.