Friday, May 14, 2010

Firebug to the rescue

Firebug has a more readable and perhaps more insightful profiler than Chrome:

My reckless use of TaffyDB is the biggest offender, with isNumeric() way out of proportion (I mean, is it a number, or isn't it?).

UPDATE:
It appears the horrendous performance suction was caused my ordering of all static data elements:
  spells.orderBy({name:"logical"});
feats.orderBy({name:"logical"});
races.orderBy({name:"logical"});
domains.orderBy({name:"logical"});
classs.orderBy({name:"logical"});
schools.orderBy({name:"logical"});
weapons.orderBy({name:"logical"});
armors.orderBy({name:"logical"});
skills.orderBy({name:"logical"});
languages.orderBy({name:"logical"});
deitys.orderBy({name:"logical"});
specials.orderBy({name:"logical"});
favored_enemys.orderBy({name:"logical"});

I found the offending block by starting and stopping the Firebug profiler between breakpoints. It posts the results in the console, in the context of the logging. Just phenomenal tool.
Down to 4 secs:This doesn't mean it will work on the iPhone, but it can't hurt.

2 comments:

Michael R. Head said...

Converting strings to doubles is a notoriously costly operation (and in XML documents containing scientific data they can easily be the bottleneck in a document parse).

isNumeric may be too generic for your needs. If you just want to know if they're integers, compare against a precompiled regexp like "[1-9][0-9]*" (or if you want to include decimal values, but not exponent/mantissa representations, try "[1-9][0-9]*(\.[0-9]+)?" )

Felonious Ham said...

This was actually getting called from the TaffyDB lib:


// ****************************************
// *
// * Create public utility isNumeric method
// * Return ture if text of sT is made up solely of numbers, false otherwise
// * Purpose: Used to determine if arguments are numbers
// *
// ****************************************
TAFFY.isNumeric = function(sT){
var vC = "0123456789";
var IsN = true;
for (var i = 0; i < sT.length && IsN == true; i++) {
if (vC.indexOf(sT.charAt(i)) == -1) {
return false;
}
}
return IsN;

};

I won't comment on the quality of the method, but his sorting algorithm could be a lot faster ;).