Notes on javascript performance

Earlier today (some would say way too early after a long night at Pure) I attended the session "How to make AJAX Applications scream on the client". This turned out to be more about general patterns in Javascript and not so much about AJAX.

Anyway here are my notes from that session:

Avoid Eval(). Instead use parameterized code.

'Switch' is costly for large sets and grows linearly. Instead use a hashtable and wrap in try/catch.

Getters/setters are inefficient. Use direct access to the variables in an instance.

DOM Instantiating and traversing is slow because it has to go from the JS layer to the DOM layer through COM. Use it as little as possible. Example:

   Bad: for(var i=0;i<100;i++) { document.getElementById('myDiv').innerHTML = i; }
   Better: var div = document.getElementById('myDiv'); for(var i=0;i<100;i++) { div.innerHTML = i; }

Use speculative download. Try and anticipate what the user needs to download next. For instance, on the login page start loading icons that the users will need after logging in. The browser might as well spend the time he is spending on entering his password on downloading stuff. When he then logs in the browser will retrieve the images from the cache instead of having to download them from the server, making the page load much quicker. Try going to the login page of an Outlook Webaccess website and see what happens behind the scenes through the Fiddler tool.

Enable GZIP encoding on the webserver. Most browsers supports it and will result in smaller downloads. Again Fiddler is great for experimenting with this.

You can see the full session online here.

Getting (re)started with Silverlight and some notes

On my way back from the Mix conference in Vegas I was trying to get one of my WPF/E applications to run on the new Silverlight 1.1alpha. It wasn't as easy as I thought it would be because a lot seems to have changed. I finally figured it out after reading Bryant Likes's blog. He already figured it out and shared the solution (Thanks Bryant!):

If you want to go the "real" route of working with Silverlight 1.1alpha, here's what you need:

I saw two really good sessions on Silverlight and .NET this morning. They are online now, and I really recommend that you watch them:

One of the really neat things are that Silverlight also supports LINQ in the client browser. Part 2 shows a cool example on that and how easy it makes it to work with data. Furthermore you can easily communicate between Browser DOM, Javascript and .NET assembly code which makes for some interesting scenarios. Since .NET excution is 400-1000 times faster than JavaScript, you could have your heavy algorithms inside silverlight, and call them from Javascript. If you don't need the presentation-layer, you could just hide it and have it as a library you utilize from JS.

So what is the main differences between v1.0 and v1.1? v1.1 contains:

  • Everything from v1.0
  • A subset of the .NET 3.5 framework and some extra browser and AJAX specific classes
  • XAML extensibility
  • Control class (for user controls)
  • Sample controls

Currently Silverlight works with Safari, Firefox and IE on both Mac and Windows and soon to be Opera as well. I asked them whether they would also support other platforms like Linux. Basically they didn't have any 'issues' with making that, but were currently not considering it until there is a larger demand for it.

Update: Mono has already announced that they will make sure we get Silverlight support on Linux. COOL!

Ajax View: Remotely Monitoring Web 2.0 Applications

Today Microsoft demoed their AjaxView application in one of the Mix07 sessions. It acts as a proxy and monitors requests, as well as execution time for each javascript function that gets executed. This is really neat for tracking what methods are putting the most load on the client browser. Now all we need is some built-in tracking of memory leaks ;-)

A tech preview will be available within the next 1-2 months.

Update: You can now see the full session where this was demoed online here.

Mix07 Keynote

The big topic of today’s keynote by Ray Ozzie & Scott Guthrie at the Mix07 was Silverlight. Today several new things were unveiled:

  • Silverlight 1.0 beta was released
  • Silverlight 1.1 alpha was released / unveiled
  • Silverlight Streaming was unveiled
  • Silverlights new community website was unveiled at www.silverlight.net
  • Blend Expression was released to day (we all got a free copy too)

And to me the biggest news of them all:

  • Silverlight 1.1 alpha has support for .NET code inside the Silverlight application!

Basically this means that you now can use C#, VB, IronPython, the all-new IronRuby (also unveiled today) and any other .NET language in an app that runs inside the browser crossbrowser AND crossplatform. Through .NET you can also work with and manipulate the HTML DOM, use REST services etc. No more JavaScripting! (and I was just about getting to a point where I really started to like JavaScript)

Scott Guthrie demoed a cool Silverlight-based chess application that used both JavaScript and C# for the AI, and had the two languages “compete” against each other. According to Scott, .NET is 400-1000 times faster than JavaScript, so it could calculate a lot more moves in the same time. Of course .NET won the simulated game :-) There were a lot of other cool Silverlight demos by non-Microsoft companies, including a kick-ass video-editing app running in your browser.

“Silverlight Streaming” (http://silverlight.live.com/) is Microsofts new website for sharing video (A Youtube killer perhaps?). You can freely sign up for 4gb space, and supports up to DVD-quality videos of up to 10mins. You can completely integrate videos streaming from Microsofts servers onto your webpage through Silverlight. So the next time you upload a really cool video to your website with the risk of overloading your server, Silverlight Streaming might be your answer.

So, Silverlight 1.0beta is out now, and will be finally released in the Summer 2007. 1.1alpha is out now too, but the final release is still to be determined. This includes a subset of the .NET framework, similar to what they did to the compact framework.

They also showed that through Visual Studio Orcas you can now remotely debug Silverlight applications that run on a Mac, set breakpoints, change properties on the fly etc. REALLY cool stuff.

Hi I’m a Mac. Hi I’m a PC and I can control you remotely! ;-)

You can download Silverlight 1.0b, 1.1a and SDKs at http://msdn2.microsoft.com/en-us/silverlight/default.aspx

So basically this means you now can use .NET for a larger array of purposes:

  • ASP.NET (Webserver)
  • XNA (XBOX)
  • CF.NET (Pocket PC/Phone)
  • Silverlight (Webclient – Crossplatform!)
  • WPF (Desktop)

I can’t wait to get started with this!

The other sessions I attended today was pretty good too (although missing most of the one I wanted the most because the hotel got my reservation screwed up), none of it was really new stuff we haven’t seen before. Hopefully there will be some more WOW tomorrow…

Going to Mix '07

The weather outside is awesome today. A shame I have to spend it getting ready for the Mix conference in Las Vegas. (but then again, I'm going to Vegas :-)

There's a lot of focus on Microsoft AJAX and SilverLight (formerly known as WPF/E) this year. Both of which I find really interesting technologies for use in Web GIS.

Some of the sessions that I plan to see are:

  • Building Rich Web Experiences using Silverlight and JavaScript for Developers
  • Using Visual Studio Codename "Orcas" to Design and Develop Rich AJAX Enabled Web Sites'
  • Using LINQ to Dramatically Improve Data Driven Development in Web Applications (By my Danish fellow Anders Hejlsberg)
  • Developing ASP.NET AJAX Controls with Silverlight
  • Go Deep with AJAX
  • How to Make AJAX Applications Scream on the Client
  • Navigating the Programmable Web
  • Accessing Data Services in the Cloud

Are you going too?

WPF: Who really need video on spinning cubes

Bob Powell have some really good comments on where the power of WPF really is. He needs performance for constantly redrawing the grid. Something GDI isn't that fast at, and which steals all the power from doing the real work:

In order to liberate the processor we need to stop it from drawing the graphics. We still need the graphics so this implies that they need to be managed somewhere else. By the graphics card itself possibly.

Strangely WPF is here with a system that can make even the most bogged-down two dimensional application fly. With the power of graphics processors on even simple display cards today, the rendering of a grid can become a trivial matter, even when it’s data-bound to a constantly changing stream of data.

Forget spinning cubes, forget cards that bounce and shatter in a waterfall of broken shards, forget plasma fields with smiling babies and dogs catching Frisbees. Show the managers in your company the benefits of freeing up those expensive processors for doing real ork and leave the graphics where they belong, on the video card.

Some of the first things I noticed about WPF was the drawing performance of it. As everyone else I was of course right away thinking of fancy interfaces with spinning cubes and what not, and hadn't really given it much thought abot applying it in an "ordinary" application with some "ordinary" controls. But after reading Bob's post it really makes sense!

So what does a Mac do?

Something I've noticed during my time here in the US, is the way companies pick on each other in the ads. It's like they are more busy talking about their competitors than themselves. I do find that pretty strange, and it definitely doesn't work on me. At least there are companies who have a policy of not mentioning competitors, which makes a lot more sense to me. Why would you even want to tell your customers that there are alternatives to your product? As a famous former danish tycoon once said: "Even bad publicity is good publicity"

Apple currently makes a lot of the "Hello I'm a Mac, and I'm a PC" ads which falls in this "pick on your competitor" category, and it's not the first time they are doing these kind of ads. OK, I must admit that the one about security is pretty funny, but what it is really that a Mac does? After watching several Mac commercials, I've come to the following conclusion: A Mac is an absolute waste of money, Apple suffers from a bad case of self-esteem and tries to make up for it by patronizing Microsoft. It’s a bit like the bullies back in the school yard who never got anywhere in life.

This is how I came to my conclusion (before you start yelling at me, I might be wrong but this is what sprang to my mind when I watched the ads):

  • Windows Security ad: Apparently Mac haven't implemented any security that will bug you, or prevent you from doing something stupid without thinking twice.
  • Surgery ad: So you can't change the hardware of a Mac and upgrade it to follow the newest advances in technology? Clever! I just buy a new one every year.
  • Tech support: So I have to settle with the webcam in the monitor, and buy a new monitor to upgrade the webcam to the latest and greatest? (and can I buy just a new monitor ? see above)
  • Meant for work: So I can't use it for anything fun?
  • Accident: So the powercord isn't properly connected to prevent you from accidentially disconnecting the cord?

OK I'm not really a Mac fan, and I'm probably the only one in the whole wide World who thinks that the white Mac and Ipod design is just plain ugly, and should be sent back to the 70s.

ArcGIS Server Team Blog

Art recently promised that there would be an ArcGIS Server Development Blog soon, and now it's there !
Check out our the new blog at http://blogs.esri.com/Dev/blogs/arcgisserver/
You can also find a link to the blog from http://blogs.esri.com

And even better! The server is also running ArcGIS Server.NET, so you can see the examples in action!

From the blog:

This blog is written directly by the ArcGIS Server Development Team.  We are very excited about the ArcGIS Server 9.2 release.  We have so much to share with the user community.  Topics will range from detailed programming information ("What is a page life cycle in the Web ADF?") to GIS methodology ("What is the best methodology to produce map caches?") for serving spatial data with ArcGIS Server.  One of the key parts to this blog will be the use of an example site.  We intend to post useful entries for our users which are linked directly to examples that we have built that you can access live from the Internet.

 

Jeremy has already put up a huge post on creating a website with cached tiles and custom tasks, including live running samples you can try.

Microsoft Earth

There's been a lot of rumours for a long time that Microsoft would make a 3D map application, and they were apparently true. They just upgraded their Local Live portal with a 3D viewer.

Whats the first thing you install?

Everytime I'm sitting down with a freshly installed PC, there is always one application I install before everything else (yeah even before antivirus software!): TotalCommander. It's my #1 application for navigating around the file system, running commands, opening/editing/zipping/unzipping/uploading/searching/multi-renaming files etc. etc. I use it so much that just using Windows Explorer to navigate to the install of TotalCommander is several agonizing seconds while thinking "God I wish I had TotalCmd to install TotalCmd" :-)

Today the first beta of the all new version 7 was released. Yepppiiiiiiii If you are new to TotalCmd, it's a great tool for quickly doing what else would require slow mouse navigation in Explorer and installing a bunch of additional applications. There's even a great set of plug-ins to make it even better! Below is a screenshot of TotalCmd configured as I like it.

Best of all: It's shareware and only $34, and you can install it on all your computers (as long as you only use one at a time, which most non-squid people do).

A little tip: In the install folder, there's a file called 'KEYBOARD.TXT'. This contains a list of keyboard shortcuts that will make your use of TotalCmd much more efficient, and discover a lot more of it's potential. I try to go through it once a month, and usually I learn some new ones everytime.

What's the first thing you install on a fresh PC?