libstdc++/4150: catastrophic performance decrease in C++ code

Jason Merrill jason@redhat.com
Sun Apr 14 19:36:00 GMT 2002


The following reply was made to PR libstdc++/4150; it has been noted by GNATS.

From: Jason Merrill <jason@redhat.com>
To: libstdc++@gcc.gnu.org
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: libstdc++/4150: catastrophic performance decrease in C++ code
Date: Mon, 15 Apr 2002 03:25:59 +0100

 --=-=-=
 
 Loren suggested defining _GLIBCPP_AVOID_FSEEK as a fix for 4150; I've tried
 it.  It avoids the useless seeks for the stdin case, but it's a rather
 Pyrrhic improvement; it also slows down execution from 0:42 to 1:50 (vs
 0:20 in 2.95).  The comment in ios.cc says that this "hurts" performance; I
 would suggest that verb isn't strong enough.  Perhaps "eviscerates".
 
 But going back to the problem without that define, the basic bug seems to
 be that after basic_filebuf::underflow() reads in a chunk of data, it then
 always rewinds the file to the beginning of that chunk.  The next time it
 gets called, it seeks ahead to the end of that chunk to read the next one.
 And so on.  So we get two useless seeks between each read.
 
 There may be a point to these seeks, but there are no comments in the code
 to justify them.  Simply tearing them out brings us up to 2.95 performance
 levels.  At least seekoff would need to be adjusted accordingly, but is
 there any reason why we can't leave the file pointer at the end of the last
 read block, rather than at the beginning as we do now?
 
 Jason
 
 
 --=-=-=
 Content-Type: text/x-patch
 Content-Disposition: inline
 
 *** include/bits/fstream.tcc.~1~	Fri Apr 12 11:28:30 2002
 --- include/bits/fstream.tcc	Mon Apr 15 02:49:14 2002
 *************** namespace std
 *** 268,280 ****
   	    {
   	      if (__testout)
   		_M_really_overflow();
 ! #if _GLIBCPP_AVOID_FSEEK
 ! 	      else if ((_M_in_cur - _M_in_beg) == 1)
 ! 		_M_file->sys_getc();
 ! #endif
 ! 	      else 
 ! 		_M_file->seekoff(_M_in_cur - _M_in_beg, 
 ! 				 ios_base::cur, ios_base::in);
   	    }
   
   	  if (__testinit || __testget)
 --- 268,275 ----
   	    {
   	      if (__testout)
   		_M_really_overflow();
 ! 	      if (_M_in_cur < _M_in_end)
 ! 		abort ();
   	    }
   
   	  if (__testinit || __testget)
 *************** namespace std
 *** 316,331 ****
   		  if (__testout)
   		    _M_out_cur = _M_in_cur;
   		  __ret = traits_type::to_int_type(*_M_in_cur);
 - #if _GLIBCPP_AVOID_FSEEK
 - 		  if (__elen == 1)
 - 		    _M_file->sys_ungetc(*_M_in_cur);
 - 		  else
 - 		    {
 - #endif
 - 		      _M_file->seekoff(-__elen, ios_base::cur, ios_base::in);
 - #if _GLIBCPP_AVOID_FSEEK
 - 		    }
 - #endif
   		}	   
   	    }
   	}
 --- 311,316 ----
 
 --=-=-=--



More information about the Gcc-prs mailing list