Speed up write performance to loop

20x speed for large numbers of queued writes by avoiding pinging between
the writer and main goroutines
This commit is contained in:
Kovid Goyal
2023-08-05 13:53:32 +05:30
parent 16132d0309
commit 2a5a89e01c
3 changed files with 44 additions and 25 deletions

View File

@@ -47,7 +47,8 @@ type Loop struct {
timers, timers_temp []*timer
timer_id_counter, write_msg_id_counter IdType
wakeup_channel chan byte
pending_writes []*write_msg
pending_writes []write_msg
tty_write_channel chan write_msg
pending_mouse_events *utils.RingBuffer[MouseEvent]
on_SIGTSTP func() error
style_cache map[string]func(...any) string
@@ -292,7 +293,7 @@ func (self *Loop) WakeupMainThread() bool {
func (self *Loop) QueueWriteString(data string) IdType {
self.write_msg_id_counter++
msg := write_msg{str: data, bytes: nil, id: self.write_msg_id_counter}
self.add_write_to_pending_queue(&msg)
self.add_write_to_pending_queue(msg)
return msg.id
}
@@ -301,7 +302,7 @@ func (self *Loop) QueueWriteString(data string) IdType {
func (self *Loop) UnsafeQueueWriteBytes(data []byte) IdType {
self.write_msg_id_counter++
msg := write_msg{bytes: data, id: self.write_msg_id_counter}
self.add_write_to_pending_queue(&msg)
self.add_write_to_pending_queue(msg)
return msg.id
}