From 2fe1e28220c543ddbf4e12ee7396e44ee85ad8e0 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 17 Apr 2015 22:23:52 +0900 Subject: Improvements in performance and memory usage I profiled fzf and it turned out that it was spending significant amount of time repeatedly converting character arrays into Unicode codepoints. This commit greatly improves search performance after the initial scan by memoizing the converted results. This commit also addresses the problem of unbounded memory usage of fzf. fzf is a short-lived process that usually processes small input, so it was implemented to cache the intermediate results very aggressively with no notion of cache expiration/eviction. I still think a proper implementation of caching scheme is definitely an overkill. Instead this commit introduces limits to the maximum size (or minimum selectivity) of the intermediate results that can be cached. --- src/matcher.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/matcher.go') diff --git a/src/matcher.go b/src/matcher.go index 0f3b409e..d01ed23e 100644 --- a/src/matcher.go +++ b/src/matcher.go @@ -34,10 +34,6 @@ const ( reqReset ) -const ( - progressMinDuration = 200 * time.Millisecond -) - // NewMatcher returns a new Matcher func NewMatcher(patternBuilder func([]rune) *Pattern, sort bool, tac bool, eventBox *util.EventBox) *Matcher { @@ -100,7 +96,9 @@ func (m *Matcher) Loop() { } if !cancelled { - m.mergerCache[patternString] = merger + if merger.Cacheable() { + m.mergerCache[patternString] = merger + } merger.final = request.final m.eventBox.Set(EvtSearchFin, merger) } -- cgit v1.2.3