Changeset 12420


Ignore:
Timestamp:
May 9, 2011, 4:16:49 AM (10 years ago)
Author:
jordan
Message:

(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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r12415 r12420  
    323323static unsigned int
    324324bandwidthClamp( const tr_bandwidth  * b,
    325                 const uint64_t        now,
     325                uint64_t              now,
    326326                tr_direction          dir,
    327327                unsigned int          byteCount )
     
    340340            if( byteCount > 0 )
    341341            {
    342                 double current = tr_bandwidthGetRawSpeed_Bps( b, now, TR_DOWN );
    343                 double desired = tr_bandwidthGetDesiredSpeed_Bps( b, TR_DOWN );
    344                 double r = desired >= 1 ? current / desired : 0;
     342                double current;
     343                double desired;
     344                double r;
     345
     346                if( now == 0 )
     347                    now = tr_time_msec( );
     348
     349                current = tr_bandwidthGetRawSpeed_Bps( b, now, TR_DOWN );
     350                desired = tr_bandwidthGetDesiredSpeed_Bps( b, TR_DOWN );
     351                r = desired >= 1 ? current / desired : 0;
    345352
    346353                     if( r > 1.0 ) byteCount = 0;
     
    361368                   unsigned int          byteCount )
    362369{
    363     const uint64_t now_msec = tr_time_msec( );
    364     return bandwidthClamp( b, now_msec, dir, byteCount );
     370    return bandwidthClamp( b, 0, dir, byteCount );
    365371}
    366372
Note: See TracChangeset for help on using the changeset viewer.