From e49f08e35fa7d7439de1df7f362c69ed188358dc Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Sat, 19 Mar 2022 13:30:07 +0100 Subject: [PATCH] statusline: update status only when necessary Update statusline only when changed to reduce cpu usage. commit 2512c0403fa4 ("statusline: implement per-account status") updates the status irrespective of whether the statusline changed or not. This can lead to high cpu usage that can be avoided. Reported-by: Jens Grassel Reported-by: inwit Signed-off-by: Koni Marti Acked-by: Robin Jarry --- widgets/account.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/widgets/account.go b/widgets/account.go index 647a3ae..5d1315c 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -32,6 +32,7 @@ type AccountView struct { msglist *MessageList worker *types.Worker state *statusline.State + update bool } func (acct *AccountView) UiConfig() config.UIConfig { @@ -113,6 +114,7 @@ func (acct *AccountView) SetStatus(setters ...statusline.SetStateFunc) { for _, fn := range setters { fn(acct.state) } + acct.update = true } func (acct *AccountView) UpdateStatus() { @@ -158,7 +160,10 @@ func (acct *AccountView) Invalidate() { } func (acct *AccountView) Draw(ctx *ui.Context) { - acct.UpdateStatus() + if acct.update { + acct.UpdateStatus() + acct.update = false + } acct.grid.Draw(ctx) }