-
Notifications
You must be signed in to change notification settings - Fork 13.2k
[libc++] __vprint_unicode_posix() has unnecessary call to fflush() #70142
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
Comments
You are right, flush shouldn't be here. |
The simplest fix is to delete |
Note to self this has been introduced in #73262 too. |
As it stands now the ostream overloads do two flushes, one is the The correct behaviour for the ostream vprint_unicode is the following:
|
Sorry for the late reply. I've been quite busy and wanted to investigate further was is considered a "native Unicode API". This is currently discussed in private e-mails but it indeed seems POSIX is considered not to have a "native Unicode API". In that case it's indeed not needed to call |
The check whether the stream is associated with a terminal or not is needed only on Windows. The flush is needed only on Windows and when the stream is terminal. The flushing is done only once before using the native Unicode API on Windows. Additionally, the correct flush is now called. In the case of C stream overloads of print(), std::fflush() should be used, and in the ostream overloads, only ostream::flush() member function should be used. Before this fix, the ostream overloads called ostream::flush() and then std::fflush(). See also https://wg21.link/LWG4044. Fixes llvm#70142
I rebased and updated the PR so it fixes the ostream overloads too. |
The check whether the stream is associated with a terminal or not is needed only on Windows. The flush is needed only on Windows and when the stream is terminal. The flushing is done only once before using the native Unicode API on Windows. Additionally, the correct flush is now called. In the case of C stream overloads of print(), std::fflush() should be used, and in the ostream overloads, only ostream::flush() member function should be used. Before this fix, the ostream overloads called ostream::flush() and then std::fflush(). See also https://wg21.link/LWG4044. Fixes llvm#70142
The check whether the stream is associated with a terminal or not is needed only on Windows. The flush is needed only on Windows and when the stream is terminal. The flushing is done only once before using the native Unicode API on Windows. Additionally, the correct flush is now called. In the case of C stream overloads of print(), std::fflush() should be used, and in the ostream overloads, only ostream::flush() member function should be used. Before this fix, the ostream overloads called ostream::flush() and then std::fflush(). See also https://wg21.link/LWG4044. Fixes llvm#70142
The check whether the stream is associated with a terminal or not is needed only on Windows. The flush is needed only on Windows and when the stream is terminal. The flushing is done only once before using the native Unicode API on Windows. Additionally, the correct flush is now called. In the case of C stream overloads of print(), std::fflush() should be used, and in the ostream overloads, only ostream::flush() member function should be used. Before this fix, the ostream overloads called ostream::flush() and then std::fflush(). See also https://wg21.link/LWG4044. Fixes llvm#70142
I have recently benchmarked The benchmark test redirects the output to |
My benchmark result with Clang 19 on macOS: Clang 19:
Apple Clang accidentally makes
|
I am aware this is a big slowdown. On my Linux system it's about 2x instead of your 6x. Let me give a short status update. I still believe the code was implemented correctly and the call to |
llvm-project/libcxx/include/print
Lines 235 to 241 in 2f4328e
In this function the following two lines are not necessary and introduce performance pessimization.
llvm-project/libcxx/include/print
Lines 237 to 238 in 2f4328e
Additionally, if you read the standard carefully http://www.eel.is/c++draft/print.fun#7.sentence-4 It says:
Although POSIX offers a way to query if a C stream goes to terminal or not, it does not have native Unicode API, so such API is never used, and flushing is not needed. A consequence of this is that on POSIX querying the C stream is not needed at all and it is another performance pessimization. The call to
__is_terminal()
is not needed here.llvm-project/libcxx/include/print
Lines 312 to 313 in 2f4328e
The text was updated successfully, but these errors were encountered: