GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 11722 - [3.4 only] Unbuffered filebuf::sgetn is slow
Summary: [3.4 only] Unbuffered filebuf::sgetn is slow
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 3.4.0
: P2 minor
Target Milestone: 3.4.3
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-30 09:06 UTC by Pétur Runólfsson
Modified: 2004-09-19 11:28 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2003-07-30 11:05:37


Attachments
Program for comparing unbuffered input performance. (685 bytes, text/plain)
2003-07-30 09:10 UTC, Pétur Runólfsson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pétur Runólfsson 2003-07-30 09:06:53 UTC
This is the same as 11378, but for input this time. The problem is the
same: basic_filebuf::xsgetn calls read for each character, but
fread_unlocked calls read only once.
Comment 1 Pétur Runólfsson 2003-07-30 09:10:34 UTC
Created attachment 4520 [details]
Program for comparing unbuffered input performance.

Here are typical results:

time ./inspeed stdio 1000000 10
0.75user 1.36system 0:02.19elapsed 96%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (92major+12minor)pagefaults 0swaps
time ./inspeed iostream 1000000 10
7.93user 12.44system 0:21.04elapsed 96%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (94major+12minor)pagefaults 0swaps

This shows that when reading 10 characters at a time, filebuf::sgetn is 10x
slower than fread_unlocked.
Comment 2 Andrew Pinski 2004-01-14 03:16:45 UTC
Is this a regression, if not move the target.
Comment 3 Pétur Runólfsson 2004-01-15 09:49:57 UTC
> Is this a regression

No. Unbuffered input doesn't work at all with any 3.x release, and 2.95.3
is just as bad as current mainline.
Comment 4 Paolo Carlini 2004-01-15 09:52:57 UTC
... still, I want to fix this before 3.4.0, since the changes are straightforward
in the light of the corresponding fix for sputn...
Comment 5 Mark Mitchell 2004-06-12 22:57:14 UTC
Postponing until 3.4.2.  Paolo, it's OK if you want to check in a patch for this
before 3.4.1, but I'm not going to hold the release for it.
Comment 6 Mark Mitchell 2004-08-29 18:55:10 UTC
Postponed until GCC 3.4.3.
Comment 7 CVS Commits 2004-09-13 22:21:41 UTC
Subject: Bug 11722

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	paolo@gcc.gnu.org	2004-09-13 22:21:34

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/std: std_fstream.h 
	libstdc++-v3/include/bits: fstream.tcc 
Added files:
	libstdc++-v3/testsuite/performance/27_io: filebuf_sgetn_unbuf.cc 

Log message:
	2004-09-13  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/11722
	* include/std/std_fstream.h (xsgetn): Declare only.
	* include/bits/fstream.tcc (xsgetn): Define, optimize for the
	always_noconv() case: when __n > __buflen, copy the available
	buffer and issue a direct read.
	* testsuite/performance/27_io/filebuf_sgetn_unbuf.cc: New.
	
	* include/bits/fstream.tcc (xsputn): Minor tweak, reorder a
	conditional.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.2657&r2=1.2658
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/std/std_fstream.h.diff?cvsroot=gcc&r1=1.62&r2=1.63
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/fstream.tcc.diff?cvsroot=gcc&r1=1.122&r2=1.123
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/performance/27_io/filebuf_sgetn_unbuf.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 CVS Commits 2004-09-19 11:26:56 UTC
Subject: Bug 11722

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	paolo@gcc.gnu.org	2004-09-19 11:26:48

Modified files:
	libstdc++-v3   : ChangeLog 
	libstdc++-v3/include/std: std_fstream.h 
	libstdc++-v3/include/bits: fstream.tcc 
Added files:
	libstdc++-v3/testsuite/performance/27_io: filebuf_sgetn_unbuf.cc 

Log message:
	2004-09-19  Paolo Carlini  <pcarlini@suse.de>
	
	* include/bits/fstream.tcc (xsgetn): Slightly tweak conditional,
	as per Nathan's original suggestion.
	
	2004-09-19  Nathan Myers  <ncm@cantrip.org>
	
	* include/bits/fstream.tcc (xsgetn): Slightly tweak the recent fix
	for 11722: copy can replace move; the common case is __avail == 0.
	
	2004-09-19  Paolo Carlini  <pcarlini@suse.de>
	
	PR libstdc++/11722
	* include/std/std_fstream.h (xsgetn): Declare only.
	* include/bits/fstream.tcc (xsgetn): Define, optimize for the
	always_noconv() case: when __n > __buflen, copy the available
	buffer and issue a direct read.
	* testsuite/performance/27_io/filebuf_sgetn_unbuf.cc: New.
	
	* include/bits/fstream.tcc (xsputn): Minor tweak, reorder a
	conditional.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2224.2.174&r2=1.2224.2.175
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/std/std_fstream.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.61&r2=1.61.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/fstream.tcc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.116.4.6&r2=1.116.4.7
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/performance/27_io/filebuf_sgetn_unbuf.cc.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.10.1

Comment 9 Paolo Carlini 2004-09-19 11:28:42 UTC
Fixed for 3.4.3.