mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-20 23:25:46 +00:00
Start the input stamp on the first byte, and read the clock once
A zero-length commit, from EOF or EAGAIN, no longer sets new_input_at. The delay is measured from the first real byte. vt_parser_input_wake() takes the caller's now. The I/O thread reads the clock once per pass instead of once per child.
This commit is contained in:
parent
2bcb49aa04
commit
b4b0beb20b
3 changed files with 11 additions and 10 deletions
|
|
@ -1848,10 +1848,10 @@ write_to_child(int fd, Screen *screen) {
|
|||
}
|
||||
|
||||
static ParserInputWake
|
||||
pending_input_wake_info(ChildMonitor *self) {
|
||||
pending_input_wake_info(ChildMonitor *self, monotonic_t now) {
|
||||
ParserInputWake info = {0};
|
||||
for (size_t i = 0; i < self->count; i++) {
|
||||
ParserInputWake one = vt_parser_input_wake(children[i].screen->vt_parser);
|
||||
ParserInputWake one = vt_parser_input_wake(children[i].screen->vt_parser, now);
|
||||
if (one.small_pending) info.small_pending = true;
|
||||
// The main thread clears input_at only when it finishes this chunk.
|
||||
if (one.large_ready && one.input_at != children[i].woken_for_input_at) info.large_ready = true;
|
||||
|
|
@ -1861,9 +1861,9 @@ pending_input_wake_info(ChildMonitor *self) {
|
|||
}
|
||||
|
||||
static void
|
||||
remember_woken_large_input(ChildMonitor *self) {
|
||||
remember_woken_large_input(ChildMonitor *self, monotonic_t now) {
|
||||
for (size_t i = 0; i < self->count; i++) {
|
||||
ParserInputWake one = vt_parser_input_wake(children[i].screen->vt_parser);
|
||||
ParserInputWake one = vt_parser_input_wake(children[i].screen->vt_parser, now);
|
||||
if (!(one.large_ready && one.input_at)) continue;
|
||||
children_mutex(lock);
|
||||
children[i].woken_for_input_at = one.input_at;
|
||||
|
|
@ -1893,7 +1893,7 @@ io_loop(void *data) {
|
|||
has_pending_wakeups = false; \
|
||||
last_wakeup_was_early = false; \
|
||||
signal_pending = false; \
|
||||
remember_woken_large_input(self); \
|
||||
remember_woken_large_input(self, now); \
|
||||
}
|
||||
|
||||
while (LIKELY(!self->shutting_down)) {
|
||||
|
|
@ -1985,7 +1985,7 @@ io_loop(void *data) {
|
|||
// streams of small writes are still coalesced.
|
||||
if (child_data_received || signal_pending || has_pending_wakeups) {
|
||||
now = monotonic();
|
||||
ParserInputWake pending = pending_input_wake_info(self);
|
||||
ParserInputWake pending = pending_input_wake_info(self, now);
|
||||
// rate_open is the gap since the previous wakeup. A large chunk the
|
||||
// parser will accept now (large_ready) wakes inside that gap. A large
|
||||
// chunk still inside input_delay waits until new_input_at + input_delay,
|
||||
|
|
|
|||
|
|
@ -1653,7 +1653,8 @@ vt_parser_commit_write(Parser *p, size_t sz) {
|
|||
with_lock {
|
||||
size_t off = self->read.sz + self->write.pending;
|
||||
// 0 means no unparsed input is waiting. monotonic() can return 0 at startup.
|
||||
if (self->new_input_at == 0) {
|
||||
// A zero-length commit must not start the clock before any byte arrives.
|
||||
if (sz && self->new_input_at == 0) {
|
||||
monotonic_t stamp = monotonic();
|
||||
self->new_input_at = stamp ? stamp : 1;
|
||||
self->fresh_input_at = off;
|
||||
|
|
@ -1675,7 +1676,7 @@ vt_parser_has_space_for_input(const Parser *p) {
|
|||
}
|
||||
|
||||
ParserInputWake
|
||||
vt_parser_input_wake(const Parser *p) {
|
||||
vt_parser_input_wake(const Parser *p, monotonic_t now) {
|
||||
PS *self = (PS *)p->state;
|
||||
ParserInputWake ans = {0};
|
||||
with_lock {
|
||||
|
|
@ -1689,7 +1690,7 @@ vt_parser_input_wake(const Parser *p) {
|
|||
else if (fresh < SMALL_PENDING_INPUT_THRESHOLD) ans.small_pending = true;
|
||||
else {
|
||||
monotonic_t ready_at = self->new_input_at + OPT(input_delay);
|
||||
if (ready_at <= monotonic()) ans.large_ready = true;
|
||||
if (ready_at <= now) ans.large_ready = true;
|
||||
else ans.large_held_until = ready_at;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,6 @@ void reset_vt_parser(Parser *);
|
|||
uint8_t *vt_parser_create_write_buffer(Parser *, size_t *);
|
||||
void vt_parser_commit_write(Parser *, size_t);
|
||||
bool vt_parser_has_space_for_input(const Parser *);
|
||||
ParserInputWake vt_parser_input_wake(const Parser *);
|
||||
ParserInputWake vt_parser_input_wake(const Parser *, monotonic_t now);
|
||||
void parse_worker(void *p, ParseData *data, bool flush);
|
||||
void parse_worker_dump(void *p, ParseData *data, bool flush);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue