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

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

https://gcc.gnu.org/g:3f1519eef5cbdcea2f18445852f5482798e3936a

commit r13-3815-g3f1519eef5cbdcea2f18445852f5482798e3936a
Author: Charles-François Natali <cf.nat...@gmail.com>
Date:   Thu Oct 6 20:02:56 2022 +0100

    libstdc++: basic_filebuf: don't flush more often than necessary [PR63746]

    `basic_filebuf::xsputn` would bypass the buffer when passed a chunk of
    size 1024 and above, seemingly as an optimisation.

    This can have a significant performance impact if the overhead of a
    `write` syscall is non-negligible, e.g. on a slow disk, on network
    filesystems, or simply during IO contention because instead of flushing
    every `BUFSIZ` (by default), we can flush every 1024 char.
    The impact is even greater with custom larger buffers, e.g. for network
    filesystems, because the code could issue `write` for example 1000X more
    often than necessary with respect to the buffer size.
    It also introduces a significant discontinuity in performance when
    writing chunks of size 1024 and above.

    Instead, it makes sense to only bypass the buffer if the amount of data
    to be written is larger than the buffer capacity.

    Signed-off-by: Charles-Francois Natali <cf.nat...@gmail.com>

    libstdc++-v3/ChangeLog:

            PR libstdc++/63746
            * include/bits/fstream.tcc (basic_filbuf::xsputn): Remove
            1024-byte chunking that bypasses the buffer for large writes.
            * testsuite/27_io/basic_filebuf/sputn/char/63746.cc: New test.

Reply via email to