Slow javascript performance in IE (string concatenation)

I’ve come to realize while IE 7 is no less than a landslide improvement over IE 6, it is still IE. While IE alone in the market appeared to be a superior product, compared to the likes of firefox it is simply inferior. Firefox script interpreter is all around faster, in my experience it is not just 2-5x faster, it can be 100x for some operations. Crazy right? I’ve been pushing the envelope with an ajax/dojo based site I’ve spent a large amount of time on. To be blunt there is more than one occasion during the development process I have had to rewrite code to accomadate the script execution of IE 7. Looking back most of the time the script was poorly thought out set of operations that needed to be rewritten anyway.

My last road block however was a particular chunk of JSON data that was packaged up base64 encoded then sent off to the server via the dojo xhrpost method. I really was scratching my head whenever I was in IE and got up to a 3-10 second delay while sending this data to the server. While in Firefox and Safari there was none. After a period of a few hours I narrowed the delay to my base64 encoding script running on the client side causing the delay. It didn’t take long start finding that IE is incredibly inefficient as string concatenation. The solution is simple.  Implement a string buffer.  I have provided some snippets along with the corrected JS file for viewing.

// addresses some speed issues with IE 
function StringBuffer()
{
this.buffer = [];
}
 
StringBuffer.prototype.append = function append(string) {
this.buffer.push(string);
return this;
};
 
StringBuffer.prototype.toString = function toString() {
return this.buffer.join("");
};
 
// end buffer
 
function encodeBase64(str){
 
...
 
var buf = new StringBuffer(); // new buffer code
 
...
 
//result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
 
buf.append(base64Chars [(( inBuffer[0] << 4 ) & 0x30) | (inBuffer[1] >> 4) ]);
 
...
 
}

Source for the entire base64 file here:
base64.js

Posted in Uncategorized | 2 Comments

Diagnose ‘File does not exist’ error in ASP.net

I have ventured deep into the land of asp.net the past few months.  Luckily the the blogsphere keeps me on track.  Every day or so I run into a nagging issue with asp.net or something I can’t quite accomplish.  I have been nearing the end of my project and have simply had a big which I could not fix.  It seems asp.net will fire an error when ANY file is missing on an asp.net webpage.  This is incredibly difficult to diagnose since the error does not contain the file that is missing!  See below for an example

MESSAGE: File does not exist.
SOURCE: System.Web
FORM:
QUERYSTRING: 695777780
TARGETSITE: Void ProcessRequestInternal(System.Web.HttpContext)
STACKTRACE: at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context)…

Catching the error is accomplished by hooking into the Application_Error event typically in the global.asax

void application_Error(object sender, EventArgs e)
{

}

K# offered a great post on just how he went about solving this issue. Basically setting a breakpoint at the above section of code to see the error when it happens. That isn’t quite enough, you’ll notice visually studio even in the watched variables has nothing that leads to the missing file. If you add a watch to ((HttpApplication)sender).Context.Request you will quickly see the exact file causing the error message.

My ultimate solution was to add the ((HttpApplication)sender).Context.Request.FilePath in all my global error logging so the file that is missing is always included in the error message.

Posted in Uncategorized | Leave a comment

Test browser compatability with multiple versions of IE

Although in the past it has not always been the case, these days you must test your sites against multiple browsers for compatibility and proper rendering.  At a bare minimum my test are against IE 7, IE 6, FireFox 2, Safari (windows), soon to be IE 8 :( and sometimes Opera.  If you can test against all of these and your site still looks and works right I would say you have covered your bases pretty well.  That may not be the best way, but again in my experience that covers 98% of who will visit your site.  One issue you will run into almost immediately is how to test your site against multiple versions of Internet Explorer on the same machine.  Microsoft offers a Virtual Pc (Free) image that is made expressly for this reason.  All you need to do is download it and mount the image and you are testing!

Posted in web | Tagged , , , | Leave a comment

Debug your javascript in style

So basically today I wanted to plug a plug-in (no pun intended) that I have really found to be invaluable to debug javascript.  The plug-in is firebug for FireFox.  In my recent dive into Dojo words cannot describe how convenient and handy firebug is.  The debug console alone is enough to make it worth while because Microsoft just doesn’t have anything like it at the moment. No need wasting my breathe explaining what all it does, click the link and see for yourself.  If you develop in javascript at all you’re missing out big time not using firebug.

Posted in coding, web | Tagged , , | Leave a comment

My first thoughts on Dojo

There is a little known (to me) javascript library out there called Dojo I dove into this week.  Basically it is a massive open source javascript library focused on UI and AJAX.  So visiting their website(very nicely done btw) and checking out some of the examples I was pretty impressed with what could be done pretty easily.  My goal during the whole process was to build a drag and drop + resizable widget which is useful for some projects I’m working on.  After a few days of tinkering I have learned a lot and see that advantages of Dojo.  It can be painfully simple to do common task using Dojo, although you need to get your hands a bit dirty if you need additional functionality out of a widget.  I was unsuccessful in getting my widget working without modifying the resizable widgets source.  I guess I’ve made new widget now altogether. 

To date my main criticism of dojo is the documentation.  I’m not going to go so far to say there isn’t any, but it is really lacking for someone that wants to do more than just the simple examples they have shown.  The book of dojo is a nice run broad rundown of things while the most useful part of it is the examples you get when you download the scripts.  On the dojo website they mention a few books out now, so I may jump on that.

It is also worth noting I have been trying to get this same functionality out of Microsoft’s ASP.net Ajax with minimal success.  I have found using a .net update panel combined with the ASP.net ajax controls can be a significant headache if you want to extend the basic features even minimally.  One would assume the onResize event invoked by a resize control would be able to trigger an update panel, think again.

Posted in coding, web | Tagged , , , | Leave a comment