Registered Member
|
KTorrent 4.0.4 with libktorrent 1.0.4 on Gentoo Linux ~amd64 in system tray with uTP enabled uses ~15% cpu on an Intel Core 2 2Ghz machine. With less torrents it's closer to 10% but not lower than that.
perf (a sampling profiler that is part of the linux kernel source) shows this for the process:
etc. I wanted to see why it spends so much time locking and unlocking mutexes. I've instrumented qtcore and libktorrent using gcc's -finstrument-functions and a short session showed these locations making the calls to QMutex::lock(), sorted by accumulated time spent in that function. Two million clock ticks (first column) is a millisecond, last column is offset of call instruction in function (useless to you):
I have made a single simple patch to the code that used to be at the top of the list (STL list::size() is O(n) while list::empty() is O(1), also if you convert "(n1+n2)>0" to "n1||n2" you can short circuit).
This contribution is small, as a cursory look has not revealed to me other such low hanging fruit. I've probably missed a few as I have not actually studied the code. Could the developers please ponder this cpu usage issue? I'm sure it can be reduced in half without removing features. Please use a profiler or instrument the code yourselves. I am willing to run test, test patches, etc. |
Moderator
|
Quite surprising that they don't cache the amount of elements in std::list, it's trivial to do.
You should try trunk, the µTP polling code has been improved somewhat, eliminating a timer and much locking which happened every time the timer fired. |
Registered Member
|
From the horse's mouth:
The rationale is that if you require a kept count, you can very easily wrap the list yourself but you can't easily remove the space and time overhead from the provided implementation. The GNU libstdc++ doxygen says:
Without reading the code you can see it's an O(n) design. Anyway, I've tried to checkout trunk from svn and anonsvn.kde.org is too slow and timed out a number of times. Is there a better mirror? Possibly using a better SCM? Or tips on how/when to get better performance from the kde svn repo? EDIT: Got a checkout. I'll measure the improvement and report here. EDIT2: It is significantly better. About twice lower cpu usage, in fact. Good job! |
Moderator
|
I'm planning another optimization round for 4.1. Hoping to shave of some more CPU usage.
|
Registered users: Bing [Bot], daret, Google [Bot], sandyvee, Sogou [Bot]