No one is going to give me happiness
I have to go get it on my own.
Oh to remember this every moment of the day, especially a bad day.
The delete operator blows on Firefox 3.0
My friend Brent and I have been refactoring for the next release of the JavaScript API we work on. One of our mini projects made me happy because I knew I would finally have a reason to use JSLitmus. One of the tests we did I believe is worth blogging about.
The scenario is that we currently use a JavaScript Array object to hold a dictionary of callback functions. We index the function in the array with the raw number used to id the request, where the raw number is a random integer from 0 to fucking-gigantic. When the server responds to our request, if there is a callback function associated with the id of the response, then we call the function and null out it’s position in the array.
Essentially:
/* initialize shit */
_callbackArray = [];
/* store shit for later */
_callbackArray[requestId] = functionToCallLater;
/* tell shit to happen */
/* shit happens */
/* catch shit, here responseId === requestId */
if ( _callbackArray[responseId] ) {
_callbackArray[responseId]();
_callbackArray[responseId] = null;
}
Brent and I were curious about:
- The memory footprint of using arbitrarily large numbers in an array
- Could we turn the _callbackArray into a _callbackDictionary where the dictionary is a simple JavaScript object we treat as a hash and get the same performance
I decided to test out the second item first. I whipped up a test on JSLitmus to check the speed of our proposed solutions:
- Baseline of our requestId random number generator
- Speed of Array object using arbitrary numeric indexes, nulling out the functions after calling
- Speed of a JS Object using arbitrary numeric hashes, nulling out the functions after calling
- Speed of a JS Object using arbitrary numeric hashes, deleting the hash reference to the functions after calling
What was interesting was how Firefox 3.0.5 on Windows choked like an amateur fluffer when executing a massive number of delete operations. JSLitmus produces cool charts, and I include them for shock value. The graphs are normalized, make sure to pay attention to the numbers (ops per second).




74 deletes per second on Firefox 3.0? It’s like JSLitmus said, “I haz failed ur deletes.” It makes me cry when IE does something better. [Ed: Opera and] Safari are majorly fucking fast, no surprise there. For thoroughness, Brent did some tests on Chrome, and while I didn’t grab the chart off his computer, it appears Chrome is just as handicapable as Firefox when it comes to running delete operations.
Grain of salt: just how many people really need to run tens of thousands of delete ops at a time? No matter the validity of this test, I think the surprise is worthy enough to file a bug with the browsers.
Misdirected Advertising
As part of the new year clean up I logged into Facebook, one of the few social networking sites that I remain a member of. I think they’re telling me I’m getting older.
