This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

*** 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 ----

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]