diff options
author | delthas <delthas@dille.cc> | 2022-02-18 17:16:22 +0100 |
---|---|---|
committer | delthas <delthas@dille.cc> | 2022-02-18 17:16:22 +0100 |
commit | bfc54b97b1ae0e5cc3b8032a0558dbc8079d5d52 (patch) | |
tree | a1c341837ab21c465cc3dea02681f5756f1491cc | |
parent | Add support for the ALL_PROXY, NO_PROXY environment variables (diff) |
Optimize URL parsing performance
According to a CPU profiling I meade, the regex applied on each incoming
message took a substantial part of the CPU time. The slowdown it caused
was noticable at startup.
This optimizes the URL parsing by eliminating fast-path cases where no
dot appears to avoid parsing the line with a regex in those cases.
-rw-r--r-- | ui/style.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/ui/style.go b/ui/style.go index 91cd2e1..4552020 100644 --- a/ui/style.go +++ b/ui/style.go @@ -120,6 +120,11 @@ func (s StyledString) Truncate(w int, tail StyledString) StyledString { var urlRegex = xurls.Relaxed() func (s StyledString) ParseURLs() StyledString { + if !strings.ContainsRune(s.string, '.') { + // fast path: no dot means no URL + return s + } + styles := make([]rangedStyle, 0, len(s.styles)) urls := urlRegex.FindAllStringIndex(s.string, -1) |