Closed

Description
Request for improvement
What version of ripgrep are you using?
compiled current master (0913972)
How did you install ripgrep?
compiled current master (0913972)
What operating system are you using ripgrep on?
Linux Mint 19.1 with kernel 4.18.0-16-lowlatency
Describe your question, feature request, or bug.
Profile guided optimization works by building the binary with profiling instrumentation first, then running the instrumented binary in a few test cases while saving runtime profiles and then using the profiles to optimize the code for example by reordering functions to improve cachability.
Using the very naive benchmark time sudo target/release/rg --with-filename --word-regexp --line-buffered a /home > /dev/null
ripgrep needed 3.7s
on avg without profile guided optimization on my system and 3.3s
with pgo.
This is how I compiled rg with pgo:
# make sure we get a profile for each run, %p will be replaced with the pid
export LLVM_PROFILE_FILE=./target/pgo/pgo-%p.profraw
# compile instrumented binary
RUSTFLAGS="-Z pgo-gen=llvm-profile-file-env-variable-overrides-this" cargo +nightly build --release
# run a few test cases (these need to be improved to cover more rg features)
target/release/rg --help > /dev/null
target/release/rg a > /dev/null
target/release/rg B --line-buffered > /dev/null
target/release/rg c --word-regexp > /dev/null
target/release/rg D --vimgrep > /dev/null
target/release/rg e --with-filename > /dev/null
target/release/rg f --unrestricted > /dev/null
target/release/rg '[A-Z]+_SUSPEND' --with-filename --word-regexp --line-buffered > /dev/null
target/release/rg h --unrestricted --with-filename --vimgrep --word-regexp --line-buffered > /dev/null
# merge profiles
rustup run nightly llvm-profdata merge -o target/pgo/pgo.profdata target/pgo/pgo*.profraw
# compile with profile in mind
RUSTFLAGS="-Z pgo-use=target/pgo/pgo.profdata" cargo +nightly build --release
pgo could speed up ripgrep quite a bit when done correctly.