GeoTrace

7 May 2007

Post-Cinco-de-Mayo-tequilla-hangover == no skydiving. Instead I knocked together a little experiment for a geographical traceroute. Not polished or well coded.

Garbage Collection in IE6

7 March 2007

I’m not an avid blogger, and when I do post it’s rarely tech related. But recently I have had cause to do some investigation into the effects of Internet Explorer’s garbage collection routines on performance, and I thought it would be useful to summarize some findings.

Eric Lippert posted about the internals of IE’s garbage collector back in September 2003, though he skimmed over the important bits, which were later noted in the comments. The crux of the problem is that IE’s script engine uses allocations to determine when to run the GC; that is after 256 variable allocations, 4096 array slot allocations, or 64kb of strings have been allocated. Not only are allocations a bad indicator of garbage, but these limits are such that any decent sized application is going to make the GC run pretty regularly.

To compound this problem, the running time of the garbage collection routine is dependent on the size of the working set (O(N^2) as described in Lippert?s article, though the results below show a linear relationship). So as your application gets bigger the garbage collection runs slower.

Back in the day this didn?t really matter, but as web applications are getting more complex there is the potential to hit a performance wall. More code being executed means the garbage collector will be run more frequently; and because the applications contain more state on the client; and have larger code bases, the object graph that the garbage collector has to traverse gets bigger.

To demonstrate the effects of this on performance I?ve used a simple benchmarking function which creates 5000 object literals with random properties, and then sorts them. The function is then run on a simple HTML page, pre-populated with a further O-objects, each with P-properties, which will always remain in scope.

The following results show the mean execution time of the create-and-sort test as O increases for constant P=50 on Firefox 2.0 (red) and IE6 (blue) on the same computer.

http://www.endoflow.com/gcbench/gc_graph.png

Try the test for yourself.

Now, the test environment is quite contrived in that it creates the literals as homogeneous global variables in a simple scope, but the effects are the same if you create objects dynamically, with scope chains exposed via event handlers and closures.

I doubt there are many web applications that are big enough to be seriously impacted by these problems, though it is worth bearing in mind, since performance is proven to be strongly linked to adoption of web apps.

Microsoft issued a hot fix that allows you to increase the allocations, this gives a significant performance boost, but you don?t want to force all your users to patch IE so this isn’t a viable solution. IE7 seems to have solved this problem by having dynamic allocation thresholds that scale to the size of your application, but rollout of IE7, particularly to corporate users, is likely to be slow for the rest of 2007. The other options can be painful and basically involve optimizing your application by reducing code size and finding the balancing point between improved performance from keeping state local and keeping your working set to a manageable size. Always explicitly dispose objects when they are no longer needed by removing event handlers and dereferencing properties.

References:

Eric Lippert’s 2003 post: “How Do The Script Garbage Collectors Work”
http://blogs.msdn.com/ericlippert/archive/2003/09/17/53038.aspx

Micrsoft Support Article: “You may experience slow performance when you view a web page that uses Jscript in Internet Explorer 6″
http://support.microsoft.com/kb/919237

Levenshtein Distance in SQL Server

11 January 2005

Merry Christmas, Happy New Year, and all that. This is a kind of dull post but I know some people who come here will find it useful:

I have found an implementation of the Levenshtein distance function in TSQL. This allows you to calculate the similarity between two strings, which is particularly useful for searching features. You will also need a simple user-defined function called MIN3 that is not listed at the above link, here’s the super quick one I wrote:

1   CREATE function Min3( @a int, @b int, @c int ) returns int AS
2   BEGIN
3   	DECLARE @Retval int
4   	if @a <= @b AND @a <= @c
5   		BEGIN
6   		SET @Retval = @a
7   		END
8   	if @b < @a AND @b <= @c
9   		BEGIN
10  		SET @Retval = @b
11  		END
12  	if @c < @a AND @c < @b
13  		BEGIN
14  		SET @Retval = @c
15  		END
16  RETURN @Retval
17  END

New IE Vulnerability

17 December 2004

A new and very dodgy vulnerability has been found in IE that allows fraudsters to create web pages that pose as other sites; and it is increadibly simple to set up. A few weeks ago an ex-colleague asked some advice after receiving an email with a link to a spoofed version of the e-commerce section of their site, so as you can see this is could be pretty nasty. You can find out more information at Secunia.com.

Basically, be very careful using e-commerce links from emails and untrusted websites. Or else use FireFox.

DHTML: Event Based Animation Demo

9 October 2004

At someone’s request I have set up an example demonstrating event based animations in DHTML. The "Toolkit" code is extracted from a Thirteenth Parallel project that never got completed, as such it is not all that stream lined or complete; however this example should illustrate a neat and quick way for developing complex animations.

To put the example into context: you could use an animation object and a 5-dimensional curve to animate an expanding panel while changing it’s colour (2d for the element’s y-position and height; 3d for the red, green and blue components of it’s colour). Also, because the animation object is not tied directly to any element or property, the on-animate event handlers could be used to animate anything from colours, widths and element positions, to frame sizes and window positions.

PHP graphing classes

14 June 2004

Not quite as interesting as my previous post on quitting my job, but nevertheless some people may be interested in this small collection of classes for drawing graphs in PHP.