mirror of
https://github.com/junegunn/fzf.git
synced 2026-03-18 12:32:40 +08:00
Replace the per-chunk query cache from []Result slices to fixed-size bitmaps (ChunkBitmap: [16]uint64 = 128 bytes per entry). Each bit indicates whether the corresponding item in the chunk matched. This reduces cache memory by 86 times in testing: - Old []Result cache: ~22KB per chunk per query (for 500 matches) - New bitmap cache: ~262 bytes per chunk per query (fixed) With the reduced per-entry cost, queryCacheMax is raised from chunkSize/5 to chunkSize/2, allowing broader queries (up to 50% match rate) to be cached while still using far less memory.
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package fzf
|
|
|
|
import (
|
|
"math"
|
|
"time"
|
|
|
|
"github.com/junegunn/fzf/src/util"
|
|
)
|
|
|
|
const (
|
|
// Core
|
|
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
|
coordinatorDelayStep time.Duration = 10 * time.Millisecond
|
|
|
|
// Reader
|
|
readerBufferSize = 64 * 1024
|
|
readerSlabSize = 128 * 1024
|
|
readerPollIntervalMin = 10 * time.Millisecond
|
|
readerPollIntervalStep = 5 * time.Millisecond
|
|
readerPollIntervalMax = 50 * time.Millisecond
|
|
|
|
// Terminal
|
|
initialDelay = 20 * time.Millisecond
|
|
initialDelayTac = 100 * time.Millisecond
|
|
spinnerDuration = 100 * time.Millisecond
|
|
previewCancelWait = 500 * time.Millisecond
|
|
previewChunkDelay = 100 * time.Millisecond
|
|
previewDelayed = 500 * time.Millisecond
|
|
maxPatternLength = 1000
|
|
maxMulti = math.MaxInt32
|
|
|
|
// Background processes
|
|
maxBgProcesses = 30
|
|
maxBgProcessesPerAction = 3
|
|
|
|
// Matcher
|
|
progressMinDuration = 200 * time.Millisecond
|
|
|
|
// Capacity of each chunk
|
|
chunkSize int = 1024
|
|
chunkBitWords = (chunkSize + 63) / 64
|
|
|
|
// Pre-allocated memory slices to minimize GC
|
|
slab16Size int = 100 * 1024 // 200KB * 32 = 12.8MB
|
|
slab32Size int = 2048 // 8KB * 32 = 256KB
|
|
|
|
// Do not cache results of low selectivity queries
|
|
queryCacheMax int = chunkSize / 2
|
|
|
|
// Not to cache mergers with large lists
|
|
mergerCacheMax int = 100000
|
|
|
|
// History
|
|
defaultHistoryMax int = 1000
|
|
|
|
// Jump labels
|
|
defaultJumpLabels string = "asdfghjklqwertyuiopzxcvbnm1234567890ASDFGHJKLQWERTYUIOPZXCVBNM`~;:,<.>/?'\"!@#$%^&*()[{]}-_=+"
|
|
)
|
|
|
|
// fzf events
|
|
const (
|
|
EvtReadNew util.EventType = iota
|
|
EvtReadFin
|
|
EvtSearchNew
|
|
EvtSearchProgress
|
|
EvtSearchFin
|
|
EvtReady
|
|
EvtQuit
|
|
)
|
|
|
|
const (
|
|
ExitOk = 0
|
|
ExitNoMatch = 1
|
|
ExitError = 2
|
|
ExitBecome = 126
|
|
ExitInterrupt = 130
|
|
)
|