You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fzf/src
Junegunn Choi 37dc273148
Micro-optimizations
- Make structs smaller
- Introduce Result struct and use it to represent matched items instead of
  reusing Item struct for that purpose
- Avoid unnecessary memory allocation
- Avoid growing slice from the initial capacity
- Code cleanup
8 years ago
..
algo Micro-optimizations 8 years ago
curses Add --preview and --preview-window 8 years ago
fzf Rewrite fzf in Go 10 years ago
util Micro-optimizations 8 years ago
Dockerfile.android Update build script 8 years ago
Dockerfile.arch Update build script 8 years ago
Dockerfile.centos Make 32-bit linux binary (partially) static (#523) 8 years ago
Dockerfile.ubuntu Update build script 8 years ago
LICENSE Update license: 2016 9 years ago
Makefile [make] Reduce the size of the binaries with `-ldflags -w` 8 years ago
README.md Update Makefile to allow build on i686 (#555) 8 years ago
ansi.go Micro-optimizations 8 years ago
ansi_test.go Micro-optimizations 8 years ago
cache.go Micro-optimizations 8 years ago
cache_test.go Micro-optimizations 8 years ago
chunklist.go Performance fix - unnecessary rune convertion on --ansi 9 years ago
chunklist_test.go Micro-optimizations 8 years ago
constants.go Increase read buffer size to 64KB 8 years ago
core.go Micro-optimizations 8 years ago
history.go Lint 9 years ago
history_test.go Fix test code for docker build 9 years ago
item.go Micro-optimizations 8 years ago
item_test.go Micro-optimizations 8 years ago
matcher.go Micro-optimizations 8 years ago
merger.go Micro-optimizations 8 years ago
merger_test.go Micro-optimizations 8 years ago
options.go Micro-optimizations 8 years ago
options_test.go [perf] Avoid allocating rune array for ascii string 8 years ago
pattern.go Micro-optimizations 8 years ago
pattern_test.go Micro-optimizations 8 years ago
reader.go Increase read buffer size to 64KB 8 years ago
reader_test.go Performance fix - unnecessary rune convertion on --ansi 9 years ago
terminal.go Micro-optimizations 8 years ago
tokenizer.go Micro-optimizations 8 years ago
tokenizer_test.go [perf] Avoid allocating rune array for ascii string 8 years ago
update_assets.rb Fix update_assets script 10 years ago

README.md

fzf in Go

fzf in go

This directory contains the source code for the new fzf implementation in Go.

Upgrade from Ruby version

The install script has been updated to download the right binary for your system. If you already have installed fzf, simply git-pull the repository and rerun the install script.

cd ~/.fzf
git pull
./install

Otherwise, follow the instruction as before. You can also install fzf using Homebrew if you prefer that way.

Motivations

No Ruby dependency

There have always been complaints about fzf being a Ruby script. To make matters worse, Ruby 2.1 removed ncurses binding from its standard libary. Because of the change, users running Ruby 2.1 or above are forced to build C extensions of curses gem to meet the requirement of fzf. The new Go version will be distributed as an executable binary so it will be much more accessible and should be easier to setup.

Performance

Many people have been surprised to see how fast fzf is even when it was written in Ruby. It stays quite responsive even for 100k+ lines, which is well above the size of the usual input.

The new Go version, of course, is significantly faster than that. It has all the performance optimization techniques used in Ruby implementation and more. It also doesn't suffer from GIL, so the search performance scales proportional to the number of CPU cores. On my MacBook Pro (Mid 2012), the new version was shown to be an order of magnitude faster on certain cases. It also starts much faster though the difference may not be noticeable.

Differences with Ruby version

The Go version is designed to be perfectly compatible with the previous Ruby version. The only behavioral difference is that the new version ignores the numeric argument to --sort=N option and always sorts the result regardless of the number of matches. The value was introduced to limit the response time of the query, but the Go version is blazingly fast (almost instant response even for 1M+ items) so I decided that it's no longer required.

System requirements

Currently, prebuilt binaries are provided only for OS X and Linux. The install script will fall back to the legacy Ruby version on the other systems, but if you have Go 1.4 installed, you can try building it yourself.

However, as pointed out in golang.org/doc/install, the Go version may not run on CentOS/RHEL 5.x, and if that's the case, the install script will choose the Ruby version instead.

The Go version depends on ncurses and some Unix system calls, so it shouldn't run natively on Windows at the moment. But it won't be impossible to support Windows by falling back to a cross-platform alternative such as termbox only on Windows. If you're interested in making fzf work on Windows, please let me know.

Build

# Build fzf executables and tarballs
make release

# Install the executable to ../bin directory
make install

# Build executables and tarballs for Linux using Docker
make linux

Contribution

For the time being, I will not add or accept any new features until we can be sure that the implementation is stable and we have a sufficient number of test cases. However, fixes for obvious bugs and new test cases are welcome.

I also care much about the performance of the implementation, so please make sure that your change does not result in performance regression. And please be noted that we don't have a quantitative measure of the performance yet.

Third-party libraries used

License

MIT