Friday, January 18, 2008

YUI JavaScript : Slowest Code Ever?

Would you believe it possible, that instead of using client-side JavaScript (YUI in this case - Yahoo User Interface code) to do something as simple as format a couple-hundred row table and offer client-side table data sorting (via column-header clicks), it is faster to do all of this via:
  1. a round-trip to a webserver,...
  2. where the webserver also roundtrips to a database server (a totally different machine, behind a firewall),...
  3. where the database server has to execute a complex stored procedure against a million or more rows of data, filter and summarize that data to a couple hundred rows, sort it, send it back to web server...
  4. where the webserver's C# ASPX code must write out the HTML and deliver it to the client's web-browser
I can't explain how insanely slow client-side JavaScript (in a browser) can be, without discussing an example I personally have experience with that demonstrates performance that is so poor your mind cannot even grasp how it is possible.

Yes, it sounds insane, but it is true - in this case, I was comparing:
using the Yahoo User Interface (YUI) Controls for a project, where the YUI datatable has been used to add formatting and column-sorting to an existing HTML table,...

VS.
...doing the sequence I first described above with round-tripping to the web-server / database-server / etc (which sounds impossibly more complex).
I'm even using a 3GHz desktop computer to run the JavaScript, and it is still slow!

The speed-comparison results:
  • Yahoo User Interface YUI datatable control - client side JavaScript version: 15 SECONDS!
  • Complete round-trip to IIS 6 web-server, SQL-Server, and C# 3.0 code to write out the same formatted HTML: LESS THAN 2 SECONDS!
My god!

Talk about an opportunity to tune that YUI Code! Or, is it the JavaScript / ECMAScript interpreter that is so insanely slow on the client? How is this even possible? When I use the YUI datatable to re-sort the 200-300 row local table, it is taking 15+ seconds each time (and that is when using FireFox 2.0 --- did I mention that Internet Explorer IE 6 takes nearly twice as long!!)

How can any code / language be this slow in modern times!!!???

Once again, I find myself remembering how I have felt all along, and still feel the same way, about web-development using HTML, JavaScript, etc -- it's complete rubbish! There are browser incompatibilities galore, rendering inconsistencies everywhere, behavior / event differences, and it is just generally the most screwed up application-development "platform" ever imagined.

The web should be no different than the desktop! Aside from super simplistic static HTML pages or generated HTML (via ASP, DotNet, PHP, Ruby, whatever) a "web site" should be nothing more than a document-presentation site. If you require real "functionality" (i.e., an "application", it is time to do things quite different.

Instead of this current web "application" model where everyone seems to continually try to beat "applications" into the shape of a web-page, we need to instead create true executable applications that run on the client machine natively. It is SO SIMPLE to create an application that can talk to remote databases over TCP/IP and/or through SOAP endpoints, etc., that I can't figure out why everything has to be a "web page" like it is now. You wait: sooner or later people will proclaim the "fat" web-client (a local EXE) the latest and greatest thing that was "invented" or "discovered" or something (instead of admitting it was just ignored and obvious!)

2 comments:

blogger said...
This comment has been removed by a blog administrator.
blogger said...
This comment has been removed by a blog administrator.