From c72f7fdb261b1e57874d59bbf99a43f0f56b6478 Mon Sep 17 00:00:00 2001 From: delthas Date: Fri, 15 Apr 2022 21:06:08 +0200 Subject: Optimize URL regex Following a quick local profiling & benchmark, matching links with regexes is by far (>50x) the most time-consuming processing we do, especially on start. Switching to a URL regex with any scheme is faster by a factor of ~x8, probably because there are many less "or" cases between a list of 100+ schemes, instead using a simple character class. --- ui/style.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/style.go b/ui/style.go index d3869c1..47904c7 100644 --- a/ui/style.go +++ b/ui/style.go @@ -118,7 +118,7 @@ func (s StyledString) Truncate(w int, tail StyledString) StyledString { return sb.StyledString() } -var urlRegex = xurls.Relaxed() +var urlRegex, _ = xurls.StrictMatchingScheme(xurls.AnyScheme) func (s StyledString) ParseURLs() StyledString { if !strings.ContainsRune(s.string, '.') { -- cgit v1.2.3