From d67b4f3bd8e831c56a2299b5af23d1e24378f541 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 11 Jun 2025 14:15:08 +0200 Subject: [PATCH] perf(rss): early return when looking for an item's author The `sanitizer.StripTags` function is calling `html.NewTokenizer`, which is allocating a 4096 bytes buffer on the heap, as well a running a complex state machine to tokenize html. There is no need to do all of this for empty strings. This commit also fixes a TrimSpace/StripTags call inversion. --- internal/reader/rss/adapter.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/reader/rss/adapter.go b/internal/reader/rss/adapter.go index 273209ef..78dd156d 100644 --- a/internal/reader/rss/adapter.go +++ b/internal/reader/rss/adapter.go @@ -169,8 +169,11 @@ func findFeedAuthor(rssChannel *RSSChannel) string { author = rssChannel.ManagingEditor case rssChannel.Webmaster != "": author = rssChannel.Webmaster + default: + return "" } - return sanitizer.StripTags(strings.TrimSpace(author)) + + return strings.TrimSpace(sanitizer.StripTags(author)) } func findEntryTitle(rssItem *RSSItem) string { @@ -258,8 +261,10 @@ func findEntryAuthor(rssItem *RSSItem) string { author = rssItem.PersonName() case strings.Contains(rssItem.Author.Inner, "