[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#319377: libapt-pkg: patches for speedup



On Sun, Apr 09, 2006 at 09:13:33AM +0300, Sami Liedes <sliedes@cc.hut.fi> was heard to say:
> Umh, sorry for a _really_ slow reply, apparently I lost or missed your
> mail somehow. I only re-found this bug now. Replying in hope that it
> is still useful :) And yes, the version number is a typo.

  Well, I'm replying late because I haven't had time to wade through email
and have had spotty Internet access lately, so there.

  I don't know about anyone else (the Ubuntu guys are depcrecating apt AIUI
and might not care), but I'd like to see the apt tools have less sucky
performance.

> >Integral_ mdz: yes, some of the idioms there are weird. I'd also think
> >    that insert(s.end(), s2.begin(), s2.end()) should be the same as s
> >    += s2.
> >Integral_ mdz: I think he changed += to push_back in some places
> >    because he changed a string to a vector
> >Integral_ which seems pointless to me
> >Integral_ unless the g++ implementation of std::string is truly
> >    atrocious
> 
> Hmm. I seem to remember that appending to a string once did take time
> linear to both the strings, however this doesn't seem to be the case
> anymore.
> 
> I wrote a small program (attached) to illustrate the effect of the
> changes I made to QuoteString. Here's some results on my computer:
> 
> $ /usr/bin/time ./test_QuoteString
> 1.99user 0.00system 0:02.03elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (0major+299minor)pagefaults 0swaps
> 
> [change the program to use QuoteString_vec instead of QuoteString_str]
> 
> $ /usr/bin/time ./test_QuoteString
> 1.39user 0.00system 0:01.49elapsed 93%CPU (0avgtext+0avgdata 0maxresident)k
> 0inputs+0outputs (0major+299minor)pagefaults 0swaps
> 
> So using a vector resulted in a 30% speedup. I also claim that
> QuoteString was a place where it made difference (or actually see the
> QuoteURI I made, an even more optimized version for URIs that makes
> more of a difference).

  If using a vector is that much faster, I wonder if we would be better off
filing a bug on libstdc++ -- string should basically act like a "vector of
chars" and I can't think of any good reason for string += to be slower than
push_back on a vector.  I don't like applying optimizations that rely on the
performance characteristics of a particular implementation.

  With respect to that change, I wonder whether the speedup is from changing
+= to push_back, or from changing += to copy() (perhaps checking for the null
terminator is expensive?).  In the latter case, how does string.append perform
compared to +=?

  Daniel

Attachment: signature.asc
Description: Digital signature


Reply to: