Skip to content
Myr

Add --threads option to control matcher concurrency

Before adoption: this commit came in with the history the project adopted, so no landing records it.

By default, fzf uses 8 * NumCPU goroutines (capped at 32) for parallel matching. --threads N overrides this to use exactly N goroutines, which is useful for benchmarking and profiling.

authored by Junegunn Choi · committed by Junegunn Choi · parent 12e24d3 · Browse files · 3 files+13 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+13 added−2 removed

  • other:+13 added−2 removed

3 files+13 added−2 removed

modified:src/core.go+1 added-1 removed
233 unmodified lines
234 return BuildPattern(cache, patternCache,235 opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward, withPos,236 opts.Filter == nil, nth, opts.Delimiter, inputRevision, runes, denylistCopy, headerLines)237 }238 matcher := NewMatcher(cache, patternBuilder, sort, opts.Tac, eventBox, inputRevision)238 matcher := NewMatcher(cache, patternBuilder, sort, opts.Tac, eventBox, inputRevision, opts.Threads)239240 // Filtering mode241 if opts.Filter != nil {242 if opts.PrintQuery {
338 unmodified lines
modified:src/matcher.go+4 added-1 removed
52 unmodified lines
53)5455// NewMatcher returns a new Matcher56func NewMatcher(cache *ChunkCache, patternBuilder func([]rune) *Pattern,57 sort bool, tac bool, eventBox *util.EventBox, revision revision) *Matcher {57 sort bool, tac bool, eventBox *util.EventBox, revision revision, threads int) *Matcher {58 partitions := min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions)59 if threads > 0 {60 partitions = threads61 }62 return &Matcher{63 cache: cache,64 patternBuilder: patternBuilder,65 sort: sort,
212 unmodified lines
modified:src/options.go+8 added
676 unmodified lines
677 WalkerRoot []string678 WalkerSkip []string679 Version bool680 Help bool681 Threads int682 Bench time.Duration683 CPUProfile string684 MEMProfile string685 BlockProfile string
2689 unmodified lines
3375 if err != nil {3376 return err3377 }3378 opts.WalkerSkip = filterNonEmpty(strings.Split(str, ","))3379 case "--threads":3380 if opts.Threads, err = nextInt("number of threads required"); err != nil {3381 return err3382 }3383 if opts.Threads < 0 {3384 return errors.New("--threads must be a positive integer")3385 }3386 case "--bench":3387 str, err := nextString("duration required (e.g. 3s, 500ms)")3388 if err != nil {3389 return err
520 unmodified lines