mirror of
https://github.com/junegunn/fzf.git
synced 2026-03-04 22:31:40 +08:00
Add --threads option to control matcher concurrency
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.
This commit is contained in:
@@ -235,7 +235,7 @@ func Run(opts *Options) (int, error) {
|
|||||||
opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward, withPos,
|
opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward, withPos,
|
||||||
opts.Filter == nil, nth, opts.Delimiter, inputRevision, runes, denylistCopy, headerLines)
|
opts.Filter == nil, nth, opts.Delimiter, inputRevision, runes, denylistCopy, headerLines)
|
||||||
}
|
}
|
||||||
matcher := NewMatcher(cache, patternBuilder, sort, opts.Tac, eventBox, inputRevision)
|
matcher := NewMatcher(cache, patternBuilder, sort, opts.Tac, eventBox, inputRevision, opts.Threads)
|
||||||
|
|
||||||
// Filtering mode
|
// Filtering mode
|
||||||
if opts.Filter != nil {
|
if opts.Filter != nil {
|
||||||
|
|||||||
@@ -54,8 +54,11 @@ const (
|
|||||||
|
|
||||||
// NewMatcher returns a new Matcher
|
// NewMatcher returns a new Matcher
|
||||||
func NewMatcher(cache *ChunkCache, patternBuilder func([]rune) *Pattern,
|
func NewMatcher(cache *ChunkCache, patternBuilder func([]rune) *Pattern,
|
||||||
sort bool, tac bool, eventBox *util.EventBox, revision revision) *Matcher {
|
sort bool, tac bool, eventBox *util.EventBox, revision revision, threads int) *Matcher {
|
||||||
partitions := min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions)
|
partitions := min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions)
|
||||||
|
if threads > 0 {
|
||||||
|
partitions = threads
|
||||||
|
}
|
||||||
return &Matcher{
|
return &Matcher{
|
||||||
cache: cache,
|
cache: cache,
|
||||||
patternBuilder: patternBuilder,
|
patternBuilder: patternBuilder,
|
||||||
|
|||||||
@@ -678,6 +678,7 @@ type Options struct {
|
|||||||
WalkerSkip []string
|
WalkerSkip []string
|
||||||
Version bool
|
Version bool
|
||||||
Help bool
|
Help bool
|
||||||
|
Threads int
|
||||||
Bench time.Duration
|
Bench time.Duration
|
||||||
CPUProfile string
|
CPUProfile string
|
||||||
MEMProfile string
|
MEMProfile string
|
||||||
@@ -3375,6 +3376,13 @@ func parseOptions(index *int, opts *Options, allArgs []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
opts.WalkerSkip = filterNonEmpty(strings.Split(str, ","))
|
opts.WalkerSkip = filterNonEmpty(strings.Split(str, ","))
|
||||||
|
case "--threads":
|
||||||
|
if opts.Threads, err = nextInt("number of threads required"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if opts.Threads < 0 {
|
||||||
|
return errors.New("--threads must be a positive integer")
|
||||||
|
}
|
||||||
case "--bench":
|
case "--bench":
|
||||||
str, err := nextString("duration required (e.g. 3s, 500ms)")
|
str, err := nextString("duration required (e.g. 3s, 500ms)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user