-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added buffering to stdout when its not a terminal #736
Conversation
Thank you very much for your contribution. This is something I wanted to look into for a long time! Before I take a closer look, I have a few questions:
And concerning the sync-channel change:
|
I switched to using a sync channel to reduce the maximum memory consumption of |
Rebased and fixed conflicts |
@sourlemon207 Are you still available to continue working on this? The CI build currently breaks to due |
@sharkdp I will try fix this during the week |
Note that Rust itself will probably do this for you in the future: rust-lang/rust#60673 rust-lang/rust#78515 I think a better approach would be to make a wrapper for |
Are you referring to the line let mut buffer = Vec::with_capacity(MAX_BUFFER_LENGTH); that buffer is there so that if there is less than MAX_BUFFER_LENGTH entries the entries will be printed in order. One rust does the buffering like c you can just replace the lines let stdout = io::stdout();
let stdout = stdout.lock();
let mut stdout = io::BufWriter::new(stdout); with let mut stdout = io::stdout().lock(); |
You're right, I did misread the patch. Some code I thought was new actually just changed indentation. I won't have time for a full review for a few days but that does seem like the right idea. By the way there are some |
&config, | ||
&wants_to_quit, | ||
); | ||
if config.interactive_terminal { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this correctly, this removes the functionality where the results are sorted if the response is fast and short enough if we aren't using an "interactive_terminal", which probably isn't desirable. I think probably the only difference here should be whether we flush the result after each result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. That would simplify the diff quite a bit too, and avoid the duplication between the branches of the if config.interactive_terminal
.
); | ||
} | ||
buffer.clear(); | ||
let r = stdout.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this chunk of code:
let r = stdout.flush();
if r.is_err() {
// Probably a broken pipe. Exit gracefully.
process::exit(ExitCode::GeneralError.into());
}
should be factored out into a function, since it is repeated a few times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking my other comment into account, it could potentially be something like:
fn maybe_flush<W: Write>(config: &Arc<Options>, stdout: &mut W>) {
if config.interactive_terminal {
if stdout.flush().is_err() {
process::exit(ExitCode::GeneralError.into());
}
}
}
let r = stdout.flush(); | ||
if r.is_err() { | ||
// Probably a broken pipe. Exit gracefully. | ||
process::exit(ExitCode::GeneralError.into()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
process::exit(ExitCode::GeneralError.into()); | |
return ExitCode::GeneralError.into(); |
I'm closing this due to inactivity. Please feel free to comment in case it should be re-opened. |
This is based on the work of sharkdp#736 by @sourlemon207. I've added the suggestion I recommended on that PR.
This is based on the work of sharkdp#736 by @sourlemon207. I've added the suggestion I recommended on that PR.
This is based on the work of #736 by @sourlemon207. I've added the suggestion I recommended on that PR.
The main changes are making the functions in output.rs generic so they accept a
BufWriter
I also changed from using a
channel
to async_channel
so the program wont use too much memory if the output device is slow.Now on my system doing
fd -uuu . / | grep testfile
actually outperforms find