Optimization of Entry Id Conversion

21 views
Skip to first unread message

Edwin Khodabakchian

unread,
May 4, 2012, 4:33:28 AM5/4/12
to Friends of the Unofficial Google Reader API
Hello,

We are working on optimizing some of our Google Reader Mobile code.
After profiling, we noticed that in our current implementation, one of
the main bottlenecks is the conversion of the Google id into the entry
id. The transformation is performed in JS using BigInteger.js. The
code looks like this:

var I64 = str2bigInt( "18446744073709551616", "10", 70, 70);

//tag:google.com,2005:reader/item/8f71f734b1d61d70 --converts into --
> -8110429648223593104
//tag:google.com,2005:reader/item/3b32d9f0d2b39cd7 --converts into --
> 4265711425423645911
//tag:google.com,2005:reader/item/0855a2a24ba00272 --converts into --
> 600564943261008498

function computeEntryId( aGoogleId )
{
if( aGoogleId == null )
return null;

// step 1 remove the "tag:google.com,2005:reader/item/"
a5586878a62930f2
var hex = aGoogleId.substring( aGoogleId.lastIndexOf( "/" ) + 1 );

// use big int library to convert in 2-complement decimal
var bigI = str2bigInt( hex, "16", 70, 70);
if( bitSize( bigI ) == 64 )
return "-" + bigInt2str( sub( I64, bigI ) , "10" );
else
return bigInt2str( bigI , "10" );
}

Each invocation costs 6-13ms to run on a mobile device.

I was wondering if there is a more efficient way to perform this
translation in javascript.

Many thanks!
Reply all
Reply to author
Forward
0 new messages