mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
(trunk libT) CPU optimization in tr_bandwidthClamp().
Don't call tr_time_msec() if it's not necessary. This was one of the top CPU sinks in profiling, so removing it is a nice improvement in cases when it's not necessary, such as when speed limiting is disabled.
This commit is contained in:
parent
c0e1cd8007
commit
3c3fda5c66
1 changed files with 12 additions and 6 deletions
|
@ -322,7 +322,7 @@ tr_bandwidthSetPeer( tr_bandwidth * b, tr_peerIo * peer )
|
|||
|
||||
static unsigned int
|
||||
bandwidthClamp( const tr_bandwidth * b,
|
||||
const uint64_t now,
|
||||
uint64_t now,
|
||||
tr_direction dir,
|
||||
unsigned int byteCount )
|
||||
{
|
||||
|
@ -339,9 +339,16 @@ bandwidthClamp( const tr_bandwidth * b,
|
|||
* clamp down harder on the bytes available */
|
||||
if( byteCount > 0 )
|
||||
{
|
||||
double current = tr_bandwidthGetRawSpeed_Bps( b, now, TR_DOWN );
|
||||
double desired = tr_bandwidthGetDesiredSpeed_Bps( b, TR_DOWN );
|
||||
double r = desired >= 1 ? current / desired : 0;
|
||||
double current;
|
||||
double desired;
|
||||
double r;
|
||||
|
||||
if( now == 0 )
|
||||
now = tr_time_msec( );
|
||||
|
||||
current = tr_bandwidthGetRawSpeed_Bps( b, now, TR_DOWN );
|
||||
desired = tr_bandwidthGetDesiredSpeed_Bps( b, TR_DOWN );
|
||||
r = desired >= 1 ? current / desired : 0;
|
||||
|
||||
if( r > 1.0 ) byteCount = 0;
|
||||
else if( r > 0.9 ) byteCount *= 0.8;
|
||||
|
@ -360,8 +367,7 @@ tr_bandwidthClamp( const tr_bandwidth * b,
|
|||
tr_direction dir,
|
||||
unsigned int byteCount )
|
||||
{
|
||||
const uint64_t now_msec = tr_time_msec( );
|
||||
return bandwidthClamp( b, now_msec, dir, byteCount );
|
||||
return bandwidthClamp( b, 0, dir, byteCount );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue