1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

perf(rss): optimize a bit BuildFeed

Calls to urllib.AbsoluteURL take a bit less than 10% of the time spent in
parser.ParseFeed, completely parsing an url only to check if it's absolute, and
if not, to make it so.

Checking if it starts with `https://` or `http://` is usually enough to find if
an url is absolute, and if is doesn't, it's always possible to fall back to
urllib.AbsoluteURL.

This also comes with the advantage of reducing heap allocations, as most of the
time spent in urllib.AbsoluteURL is heap-related (de)allocations.
This commit is contained in:
jvoisin 2025-06-09 14:58:36 +02:00 committed by Frédéric Guillot
parent 0086e0b356
commit 0caadf82f2
2 changed files with 6 additions and 3 deletions

View file

@ -35,8 +35,8 @@ func (r *RSSAdapter) BuildFeed(baseURL string) *model.Feed {
} }
// Ensure the Site URL is absolute. // Ensure the Site URL is absolute.
if siteURL, err := urllib.AbsoluteURL(baseURL, feed.SiteURL); err == nil { if absoluteSiteURL, err := urllib.AbsoluteURL(baseURL, feed.SiteURL); err == nil {
feed.SiteURL = siteURL feed.SiteURL = absoluteSiteURL
} }
// Try to find the feed URL from the Atom links. // Try to find the feed URL from the Atom links.

View file

@ -21,7 +21,10 @@ func IsAbsoluteURL(link string) bool {
// AbsoluteURL converts the input URL as absolute URL if necessary. // AbsoluteURL converts the input URL as absolute URL if necessary.
func AbsoluteURL(baseURL, input string) (string, error) { func AbsoluteURL(baseURL, input string) (string, error) {
if strings.HasPrefix(input, "//") { if strings.HasPrefix(input, "//") {
input = "https://" + input[2:] return "https:" + input, nil
}
if strings.HasPrefix(input, "https://") || strings.HasPrefix(input, "http://") {
return input, nil
} }
u, err := url.Parse(input) u, err := url.Parse(input)