From 4240f1fbfd095724bcbb0ea49cfa561c973ba6ce Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sun, 3 Jul 2022 10:11:13 -0500 Subject: perf: reduce calls to GetUiConfig GetUiConfig was being called many times, and came up as a high CPU user in a cpuprofile. Every call would merge a UIConfig, which is a costly operation. Ideally, we would only need to have a config for every account X every directory. We also have a context for subjects. This patch stores all FOLDER and ACCOUNT level configs and reuses those merged objects. The SUBJECT contexts are not stored in favor of merging on-the-go, with a TODO comment to deprecate that feature and implement a better per-message styling option. I suspect this feature is not used very much. Before applying this patch with my setup, GetUiConfig is called 1159 times just to open aerc. After applying, this is reduced to 37. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- widgets/msglist.go | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'widgets/msglist.go') diff --git a/widgets/msglist.go b/widgets/msglist.go index df24526..ec14e79 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -194,14 +194,23 @@ func (ml *MessageList) drawRow(textWidth int, ctx *ui.Context, uid uint32, row i return false } - confParams := map[config.ContextType]string{ - config.UI_CONTEXT_ACCOUNT: acct.AccountConfig().Name, - config.UI_CONTEXT_FOLDER: acct.Directories().Selected(), - } - if msg.Envelope != nil { - confParams[config.UI_CONTEXT_SUBJECT] = msg.Envelope.Subject + // TODO deprecate subject contextual UIs? Only related setting is styleset, + // should implement a better per-message styling method + // Check if we have any applicable ContextualUIConfigs + confs := ml.aerc.conf.GetContextualUIConfigs() + uiConfig := acct.Directories().UiConfig() + for _, c := range confs { + if c.ContextType == config.UI_CONTEXT_SUBJECT && msg.Envelope != nil { + if c.Regex.Match([]byte(msg.Envelope.Subject)) { + confParams := map[config.ContextType]string{ + config.UI_CONTEXT_ACCOUNT: acct.AccountConfig().Name, + config.UI_CONTEXT_FOLDER: acct.Directories().Selected(), + config.UI_CONTEXT_SUBJECT: msg.Envelope.Subject, + } + uiConfig = ml.conf.GetUiConfig(confParams) + } + } } - uiConfig := ml.conf.GetUiConfig(confParams) msg_styles := []config.StyleObject{} // unread message -- cgit v1.2.3