Stdout and StdoutLock already write to a LineWriter, which is a newline-flushing BufWriter. Are you adding another BufWriter layer just to batch that even further?
Tbh, the best performance way to print to stdout is to build up a String and then print it all at once, which can be done without touching a stdout lock or bufwriter (though is theoretically isomorphic to an infinitely buffered bufwriter).
That said, I would not be against an owned variant of StdoutLock and ways of tweaking stdout's internal buffering, so long as it doesn't hurt the common case (println!) performance.
I ran into another reason to have an into_locked()-like function:
Today I tried to do this:
let stdout = std::io::stdout();
let verbose: Box<dyn Write+Send>;
if is_verbose
{ verbose = Box::new(stdout.lock()) as _; }
else
{ verbose = Box::new(std::io::sink()) as _; }
let verbose = Mutex::new(verbose);
// ... spawn thread
This isn't allowed because the locked stdout needs to have a non-Send reference to the unlocked stdout. So I need to just lock the locked stdout with the Mutex, which is too many locks!