summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordelthas <delthas@dille.cc>2022-04-15 14:55:53 +0200
committerdelthas <delthas@dille.cc>2022-04-15 14:55:53 +0200
commit717ab5ad405bed8097cc3d07cf82cc14d7b362ca (patch)
tree21df1232e45123a0a19943c6dba6fbbce3034342
parentOnly send READ for messages received from a channel (diff)
Batch events by time period rather than by fixed size
Previously, we would render every 64 events (at most). Now that we have many more events, with history & read, batch events by period rather than static size. Waiting up to 200ms before refreshing is a good compromise between responsiveness and performance.
-rw-r--r--app.go46
1 files changed, 27 insertions, 19 deletions
diff --git a/app.go b/app.go
index 9fb6a2d..e6a7b4b 100644
--- a/app.go
+++ b/app.go
@@ -18,7 +18,7 @@ import (
"github.com/gdamore/tcell/v2"
)
-const eventChanSize = 64
+const eventChanSize = 1024
func isCommand(input []rune) bool {
// Command can't start with two slashes because that's an escape for
@@ -194,31 +194,26 @@ func (app *App) SetLastClose(t time.Time) {
func (app *App) eventLoop() {
defer app.win.Close()
- evs := make([]event, 0, eventChanSize)
for !app.win.ShouldExit() {
ev := <-app.events
- evs = evs[:0]
- evs = append(evs, ev)
- Batch:
- for i := 0; i < eventChanSize; i++ {
+ if !app.handleEvent(ev) {
+ return
+ }
+ deadline := time.NewTimer(200 * time.Millisecond)
+ outer:
+ for {
select {
+ case <-deadline.C:
+ break outer
case ev := <-app.events:
- evs = append(evs, ev)
- default:
- break Batch
- }
- }
-
- for _, ev := range evs {
- if ev.src == "*" {
- if ev.content == nil {
+ if !app.handleEvent(ev) {
return
}
- if !app.handleUIEvent(ev.content) {
- return
+ default:
+ if !deadline.Stop() {
+ <-deadline.C
}
- } else {
- app.handleIRCEvent(ev.src, ev.content)
+ break outer
}
}
@@ -247,6 +242,19 @@ func (app *App) eventLoop() {
}
}()
}
+func (app *App) handleEvent(ev event) bool {
+ if ev.src == "*" {
+ if ev.content == nil {
+ return false
+ }
+ if !app.handleUIEvent(ev.content) {
+ return false
+ }
+ } else {
+ app.handleIRCEvent(ev.src, ev.content)
+ }
+ return true
+}
// ircLoop maintains a connection to the IRC server by connecting and then
// forwarding IRC events to app.events repeatedly.