public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
@ 2020-03-23  9:08 euloanty at live dot com
  2020-03-23  9:15 ` [Bug libstdc++/94268] " euloanty at live dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-23  9:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

            Bug ID: 94268
           Summary: std::filebuf is extremely (at least 10x) slow on
                    windows compared to Linux. Even much slower MSVC STL
                    with terrible ABI.
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: euloanty at live dot com
  Target Milestone: ---

Even the hacks work the same result.

https://bitbucket.org/ejsvifq_mabmip/fast_io/src/reserver_test/benchmarks/0000.10m_size_t/unit/filebuf_io_observer.cc

D:\hg\w4\f8\fast_io\benchmarks\0000.10m_size_t\unit>g++ -o filebuf_io_observer
filebuf_io_observer.cc -Ofast -std=c++2a -s

D:\hg\w4\f8\fast_io\benchmarks\0000.10m_size_t\unit>filebuf_io_observer
output: 0.5130060000000001s
input:  0.256011s

running the same program on Linux WSL2

cqwrteur@Home-Server:~/myhome/fast_io/benchmarks/0000.10m_size_t/unit$ g++ -o
filebuf_io_observer filebuf_io_observer.cc
 -Ofast -std=c++2a -s
cqwrteur@Home-Server:~/myhome/fast_io/benchmarks/0000.10m_size_t/unit$
./filebuf_io_observer
output: 0.058395978s
input:  0.06603426700000001s

It is not possible to be an optimization problem since my code has no
difference on windows and linux. I think the only reason is FILE*'s issue.
I guess the problem is just that code relies on unknown libc does not correctly
on windows. One explanation might be the underlining FILE* buffer size's
problem. I think you guys need to try larger buffer size.

Same program builds with MSVC STL (Their ABIs are terrible)
MSVC STL with hacking:
D:\hg\w4\f8\fast_io\benchmarks\0000.10m_size_t\unit>filebuf_io_observer
output: 0.119666s
input:  0.2497127s

Other comparison benchmarks

GCC 10.0.1 with msvcrt hacking.
https://bitbucket.org/ejsvifq_mabmip/fast_io/src/reserver_test/include/fast_io_legacy_impl/c/msvcrt.h

D:\hg\w4\f8\fast_io\benchmarks\0000.10m_size_t\unit>c_file_unlocked
output: 0.09216600000000001s
input:  0.12230700000000001s

GCC

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
@ 2020-03-23  9:15 ` euloanty at live dot com
  2020-03-23  9:17 ` euloanty at live dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-23  9:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

fdlbxtqi <euloanty at live dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
               Host|                            |Windows 10. MinGW-W64
             Target|                            |gcc 10.0

--- Comment #1 from fdlbxtqi <euloanty at live dot com> ---
https://bitbucket.org/ejsvifq_mabmip/mingw-gcc/src/master/
You can try with this MinGW-GCC 10. I have found this issue for a very long
time. It looks like std::filebuf does not set buffer size correctly or other
weird issues with underlining msvcrt.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
  2020-03-23  9:15 ` [Bug libstdc++/94268] " euloanty at live dot com
@ 2020-03-23  9:17 ` euloanty at live dot com
  2020-03-23  9:36 ` euloanty at live dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-23  9:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #2 from fdlbxtqi <euloanty at live dot com> ---
The hacking code is here.

https://bitbucket.org/ejsvifq_mabmip/fast_io/src/reserver_test/include/fast_io_legacy_impl/cpp/libstdc%2B%2B_libc%2B%2B.h
https://bitbucket.org/ejsvifq_mabmip/fast_io/src/reserver_test/include/fast_io_legacy_impl/cpp/general.h
https://bitbucket.org/ejsvifq_mabmip/fast_io/src/reserver_test/include/fast_io_legacy_impl/cpp/streambuf_io_observer.h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
  2020-03-23  9:15 ` [Bug libstdc++/94268] " euloanty at live dot com
  2020-03-23  9:17 ` euloanty at live dot com
@ 2020-03-23  9:36 ` euloanty at live dot com
  2020-03-23  9:38 ` euloanty at live dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-23  9:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #3 from fdlbxtqi <euloanty at live dot com> ---
I have found out the reason. It is because the buffer size is too small on the
windows. BUFSIZ == 512

You need to set the value to 4096 at least. I think even 65536 is something
should be done since the windows syscall is extremely expensive. I have tested
with WriteFile, the maximum performance needs to set to 131072 buffer_size with
my library.

I think I can fix this bug easily.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
                   ` (2 preceding siblings ...)
  2020-03-23  9:36 ` euloanty at live dot com
@ 2020-03-23  9:38 ` euloanty at live dot com
  2020-03-23  9:44 ` euloanty at live dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-23  9:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #4 from fdlbxtqi <euloanty at live dot com> ---
(In reply to fdlbxtqi from comment #3)
> I have found out the reason. It is because the buffer size is too small on
> the windows. BUFSIZ == 512
> 
> You need to set the value to 4096 at least. I think even 65536 is something
> should be done since the windows syscall is extremely expensive. I have
> tested with WriteFile, the maximum performance needs to set to 131072
> buffer_size with my library.
> 
> I think I can fix this bug easily.

The most efficient one is 1048576. However, I think it should be set to at
least 65536, although 4096 can already fix most of the problems. Windows
syscall is expensive.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
                   ` (3 preceding siblings ...)
  2020-03-23  9:38 ` euloanty at live dot com
@ 2020-03-23  9:44 ` euloanty at live dot com
  2020-03-23 11:20 ` euloanty at live dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-23  9:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #5 from fdlbxtqi <euloanty at live dot com> ---
Here is the proof.

https://bitbucket.org/ejsvifq_mabmip/fast_io/src/reserver_test/benchmarks/0000.10m_size_t/unit/streambuf_io_observer___gnu_cxx_stdio_filebuf.cc

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
                   ` (4 preceding siblings ...)
  2020-03-23  9:44 ` euloanty at live dot com
@ 2020-03-23 11:20 ` euloanty at live dot com
  2020-03-23 12:29 ` euloanty at live dot com
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-23 11:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #6 from fdlbxtqi <euloanty at live dot com> ---
Created attachment 48086
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48086&action=edit
simple patch

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
                   ` (5 preceding siblings ...)
  2020-03-23 11:20 ` euloanty at live dot com
@ 2020-03-23 12:29 ` euloanty at live dot com
  2020-03-24  1:41 ` euloanty at live dot com
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-23 12:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #7 from fdlbxtqi <euloanty at live dot com> ---
I rebuilt a new GCC with this patch. The performance improves for 10 times for
output integer. 3 times for input integer. Definitely worth it.

D:\hg\w4\f8\fast_io\benchmarks\0000.10m_size_t\unit>gcc --version
gcc (master HEAD with MCF thread model, built by cqwrteur.) 10.0.1 20200323
(experimental)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

D:\hg\w4\f8\fast_io\benchmarks\0000.10m_size_t\unit>g++ -o filebuf_io_observer
filebuf_io_observer.cc -Ofast -std=c++2a -s

D:\hg\w4\f8\fast_io\benchmarks\0000.10m_size_t\unit>filebuf_io_observer
output: 0.047s
input:  0.085998s

D:\hg\w4\f8\fast_io\benchmarks\0000.10m_size_t\unit>g++ -o filebuf_io_observer
filebuf_io_observer.cc -Ofast -std=c++2a -s -flto

D:\hg\w4\f8\fast_io\benchmarks\0000.10m_size_t\unit>filebuf_io_observer
output: 0.042999s
input:  0.086012s


Ther performance is now nearly as good as my buffer implementation. Though it
is still slower due to hacking. It is actually usable.
g++ -o iobuf_file iobuf_file.cc -Ofast -std=c++2a -s -flto


./iobuf_file.exe
output: 0.044000000000000004s
input:  0.076s

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
                   ` (6 preceding siblings ...)
  2020-03-23 12:29 ` euloanty at live dot com
@ 2020-03-24  1:41 ` euloanty at live dot com
  2020-03-30  9:17 ` euloanty at live dot com
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-24  1:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #8 from fdlbxtqi <euloanty at live dot com> ---
Well. These links are dead. Repost them.
https://bitbucket.org/ejsvifq_mabmip/fast_io/src/master/benchmarks/0000.10m_size_t/unit/filebuf_io_observer.cc
https://bitbucket.org/ejsvifq_mabmip/fast_io/src/master/benchmarks/0000.10m_size_t/unit/streambuf_io_observer___gnu_cxx_stdio_filebuf.cc
https://bitbucket.org/ejsvifq_mabmip/fast_io/src/master/benchmarks/0000.10m_size_t/unit/c_file_unlocked.cc

https://bitbucket.org/ejsvifq_mabmip/fast_io/src/master/include/fast_io_legacy_impl/cpp/libstdc%2B%2B_libc%2B%2B.h
https://bitbucket.org/ejsvifq_mabmip/fast_io/src/master/include/fast_io_legacy_impl/cpp/general.h
https://bitbucket.org/ejsvifq_mabmip/fast_io/src/master/include/fast_io_legacy_impl/cpp/streambuf_io_observer.h
https://bitbucket.org/ejsvifq_mabmip/fast_io/src/master/include/fast_io_legacy_impl/c/msvcrt.h

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
                   ` (7 preceding siblings ...)
  2020-03-24  1:41 ` euloanty at live dot com
@ 2020-03-30  9:17 ` euloanty at live dot com
  2020-05-25  0:23 ` euloanty at live dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-03-30  9:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #9 from fdlbxtqi <euloanty at live dot com> ---
https://github.com/microsoft/WSL/issues/3898

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
                   ` (8 preceding siblings ...)
  2020-03-30  9:17 ` euloanty at live dot com
@ 2020-05-25  0:23 ` euloanty at live dot com
  2020-10-28 13:19 ` cvs-commit at gcc dot gnu.org
  2020-10-28 13:25 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: euloanty at live dot com @ 2020-05-25  0:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #10 from fdlbxtqi <euloanty at live dot com> ---
What about adding another check when BUFSIZ is smaller than 4KB? If it is
smaller than 4kb, adjust the filebuf size to 4kb at least.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
                   ` (9 preceding siblings ...)
  2020-05-25  0:23 ` euloanty at live dot com
@ 2020-10-28 13:19 ` cvs-commit at gcc dot gnu.org
  2020-10-28 13:25 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-28 13:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:0bc199fc5d4eef5a20ced20df892e5e3b8821b60

commit r11-4479-g0bc199fc5d4eef5a20ced20df892e5e3b8821b60
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Oct 28 13:19:21 2020 +0000

    libstdc++: Override BUFSIZ for Windows targets [PR 94268]

    This replaces uses of BUFSIZ with a new _GLIBCXX_BUFSIZ macro that can
    be overridden in target-specific config headers.

    That allows the mingw and mingw-w64 targets to override it, because
    BUFSIZ is apparently defined to 512, resulting in poor performance. The
    MSVCRT stdio apparently uses 4096, so we use that too.

    libstdc++-v3/ChangeLog:

            PR libstdc++/94268
            * config/os/mingw32-w64/os_defines.h (_GLIBCXX_BUFSIZ):
            Define.
            * config/os/mingw32/os_defines.h (_GLIBCXX_BUFSIZ):
            Define.
            * include/bits/fstream.tcc: Use _GLIBCXX_BUFSIZ instead
            of BUFSIZ.
            * include/ext/stdio_filebuf.h: Likewise.
            * include/std/fstream (_GLIBCXX_BUFSIZ): Define.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug libstdc++/94268] std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI.
  2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
                   ` (10 preceding siblings ...)
  2020-10-28 13:19 ` cvs-commit at gcc dot gnu.org
@ 2020-10-28 13:25 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-28 13:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94268

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
   Target Milestone|---                         |11.0

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Changed to 4096 for mingw and mingw-w64 in GCC 11.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-10-28 13:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23  9:08 [Bug libstdc++/94268] New: std::filebuf is extremely (at least 10x) slow on windows compared to Linux. Even much slower MSVC STL with terrible ABI euloanty at live dot com
2020-03-23  9:15 ` [Bug libstdc++/94268] " euloanty at live dot com
2020-03-23  9:17 ` euloanty at live dot com
2020-03-23  9:36 ` euloanty at live dot com
2020-03-23  9:38 ` euloanty at live dot com
2020-03-23  9:44 ` euloanty at live dot com
2020-03-23 11:20 ` euloanty at live dot com
2020-03-23 12:29 ` euloanty at live dot com
2020-03-24  1:41 ` euloanty at live dot com
2020-03-30  9:17 ` euloanty at live dot com
2020-05-25  0:23 ` euloanty at live dot com
2020-10-28 13:19 ` cvs-commit at gcc dot gnu.org
2020-10-28 13:25 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).