diff options
author | Charles-François Natali <cf.natali@gmail.com> | 2022-10-06 20:02:56 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-11-08 17:35:14 +0000 |
commit | 3f1519eef5cbdcea2f18445852f5482798e3936a (patch) | |
tree | 7ae06d2f60d23108049a0a1133ed2fcd38097617 /gcc | |
parent | c93baa93df2d454f329a38686affcfe1a1339766 (diff) | |
download | gcc-3f1519eef5cbdcea2f18445852f5482798e3936a.zip gcc-3f1519eef5cbdcea2f18445852f5482798e3936a.tar.gz gcc-3f1519eef5cbdcea2f18445852f5482798e3936a.tar.bz2 |
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.natali@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.
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions