mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-08-04 21:52:54 +02:00
ripgrep: use new BufferedStandardStream from termcolor
Specifically, this will use a buffered writer when not printing to a tty. This fixes a long standing performance regression where ripgrep would slow down dramatically if it needed to report a lot of matches. Fixes #955
This commit is contained in:
@ -228,8 +228,13 @@ impl Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new writer for single-threaded searching with color support.
|
/// Create a new writer for single-threaded searching with color support.
|
||||||
pub fn stdout(&self) -> termcolor::StandardStream {
|
pub fn stdout(&self) -> Box<termcolor::WriteColor> {
|
||||||
termcolor::StandardStream::stdout(self.color_choice)
|
if atty::is(atty::Stream::Stdout) {
|
||||||
|
Box::new(termcolor::StandardStream::stdout(self.color_choice))
|
||||||
|
} else {
|
||||||
|
Box::new(
|
||||||
|
termcolor::BufferedStandardStream::stdout(self.color_choice))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a handle to stdout for filtering search.
|
/// Returns a handle to stdout for filtering search.
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -165,8 +165,7 @@ fn run_parallel(args: &Arc<Args>) -> Result<u64> {
|
|||||||
|
|
||||||
fn run_one_thread(args: &Arc<Args>) -> Result<u64> {
|
fn run_one_thread(args: &Arc<Args>) -> Result<u64> {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
let stdout = args.stdout();
|
let mut stdout = args.stdout();
|
||||||
let mut stdout = stdout.lock();
|
|
||||||
let mut worker = args.worker();
|
let mut worker = args.worker();
|
||||||
let mut paths_searched: u64 = 0;
|
let mut paths_searched: u64 = 0;
|
||||||
let mut match_line_count = 0;
|
let mut match_line_count = 0;
|
||||||
@ -223,8 +222,7 @@ fn run_files_parallel(args: Arc<Args>) -> Result<u64> {
|
|||||||
let print_args = Arc::clone(&args);
|
let print_args = Arc::clone(&args);
|
||||||
let (tx, rx) = mpsc::channel::<ignore::DirEntry>();
|
let (tx, rx) = mpsc::channel::<ignore::DirEntry>();
|
||||||
let print_thread = thread::spawn(move || {
|
let print_thread = thread::spawn(move || {
|
||||||
let stdout = print_args.stdout();
|
let mut printer = print_args.printer(print_args.stdout());
|
||||||
let mut printer = print_args.printer(stdout.lock());
|
|
||||||
let mut file_count = 0;
|
let mut file_count = 0;
|
||||||
for dent in rx.iter() {
|
for dent in rx.iter() {
|
||||||
if !print_args.quiet() {
|
if !print_args.quiet() {
|
||||||
@ -254,8 +252,7 @@ fn run_files_parallel(args: Arc<Args>) -> Result<u64> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_files_one_thread(args: &Arc<Args>) -> Result<u64> {
|
fn run_files_one_thread(args: &Arc<Args>) -> Result<u64> {
|
||||||
let stdout = args.stdout();
|
let mut printer = args.printer(args.stdout());
|
||||||
let mut printer = args.printer(stdout.lock());
|
|
||||||
let mut file_count = 0;
|
let mut file_count = 0;
|
||||||
for result in args.walker() {
|
for result in args.walker() {
|
||||||
let dent = match get_or_log_dir_entry(
|
let dent = match get_or_log_dir_entry(
|
||||||
@ -277,8 +274,7 @@ fn run_files_one_thread(args: &Arc<Args>) -> Result<u64> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_types(args: &Arc<Args>) -> Result<u64> {
|
fn run_types(args: &Arc<Args>) -> Result<u64> {
|
||||||
let stdout = args.stdout();
|
let mut printer = args.printer(args.stdout());
|
||||||
let mut printer = args.printer(stdout.lock());
|
|
||||||
let mut ty_count = 0;
|
let mut ty_count = 0;
|
||||||
for def in args.type_defs() {
|
for def in args.type_defs() {
|
||||||
printer.type_def(def);
|
printer.type_def(def);
|
||||||
|
Reference in New Issue
Block a user