Performance improvement in print_endline for redirection#1399
Performance improvement in print_endline for redirection#1399ytomino wants to merge 1 commit intoocaml:trunkfrom
Conversation
|
Sorry, tests/lib-dynlink-bytecode is failed. |
|
FWIW, if you are worried about the performance impact of flushing, you can always use IMHO not flushing when redirecting to files does not seem a good idea. |
I agree. tests/lib-dynlink-bytecode aware me of that this change would break many existing codes calling some large C parts, or mixing stdout and stderr. It's unacceptable. IMHO, most libraries (including other language runtimes) are using C stdio. So the OCaml's I/O is inferior to them in the case of writing a kind of application like filter command that requires speed in files and immediate flushing in CUI. Using |
|
Nicolás Ojeda Bär (2017/10/05 05:00 +0000):
IMHO *not* flushing when redirecting to files does not seem a good
idea.
I share this opinion.
|
This PR inserts checking
isattyand avoids the callingcaml_ml_flushinprint_endline,print_newline,prerr_endline, andprerr_newline.Motivation
OCaml's I/O routines is very fast because using not C stdio but the original buffering.
However, the family of
print_endlineare exceptions. They makes I/O would become slow, mainly, in the case that the standard I/O is redirected.C stdlib checks
isattyto avoidfflushon outputting '\n' for the performance.It is desirable that OCaml's I/O be revised likewise.
Details of implementation
Add new flag
CHANNEL_FLAG_ISATTYintoflagsofstruct channel, and refer it to reduce the callingisatty, because, generally speaking, system calls are slower than normal functions.(This flag may be useful for other future uses ??)
Thanks.