-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
IO: remove flush_on_newline
and only sync
on TTY devices
#7470
IO: remove flush_on_newline
and only sync
on TTY devices
#7470
Conversation
cdf0a79
to
27fb3f5
Compare
Maybe I'd use a String.build in logger's default formatter, to avoid too many sync writes, but that can wait / be benchmarked to see if there is any real benefit. |
27fb3f5
to
e2a460a
Compare
This seems to me like a bad idea, since pipes are not TTYs, this will break crystal programs which are run as subprocesses and cause hangs. I suggest making STDIO sync always. If people need more performance they can always turn it off. |
I've run across this again, I've written a program which implements the i3bar protocol which streams JSON over Does anyone have any comments on my above suggestion or I'll create a PR to make STDIO always sync. |
I don't understand why this is a problem in Crystal but not in Ruby. |
@asterite I've just looked at ruby and python, they take the approach from this PR: behaving differently based on whether the output is a TTY or not. So it's clearly debatable, I just think that choosing consistency over performance is better. People can always turn off |
Fixes #7431
Explanation for this here
Merging this or not is still debatable, but the pros I see are:
flush_on_newline
property that's actually a hack to be able to see TTY output as it's written, whensync
does that in a more unified way (and works too if you callio.print
). This also simplifies code because there's less code :-)I checked and
Logger
already flushes the IO when a message is written to it.