Google hopes to better the Web with Dart, but Microsoft has declared itself an opponent of the programming language rather than a potentially valuable ally.

Google hopes Dart will address shortcomings in JavaScript, the programming language that endows Web sites with some brains. In a blog post yesterday, though, Microsoft said that improving JavaScript is the way to go.

Five members of Microsoft's JavaScript team said the Dart sales pitch argues "JavaScript has fundamental flaws, and to support these scenarios requires a 'clean break' from JavaScript...We disagree with this point of view."

Dart got off to a rough start, with Google alienating some potential allies with an insular early-stage development process. And allies are key: For Dart to live up to its potential, it needs support among browser makers. Microsoft's stance makes it look like it'll be very hard to build that support into Internet Explorer. In addition, Microsoft remains influential with programmers, and it just offered a very public vote of no confidence.

JavaScript has the classic benefits of an incumbent technology. Programmers are familiar with it, newer browsers are remarkably faster at running it, and many libraries of pre-written software such as jQuery make powerful features easily accessible to Web developers. Such factors mean a virtuous cycle of steady improvement that makes it harder for a more revolutionary approach to gain a foothold.

And there are more improvements on the way--from Microsoft, from Mozilla, and yes, from Google itself, which continues to improve its JavaScript technology even as it preaches the gospel of Dart.

The rise of JavaScript

JavaScript began as a project at Netscape, back before Internet Explorer defeated it in the first browser war of the 1990s. Its name notwithstanding, JavaScript isn't actually related to Java, the Sun Microsystems language just becoming popular in the mid-1990s, though Sun co-founder Bill Joy supported JavaScript as an easy-to-use companion to Java, said language creator and Mozilla Chief Technology Officer Brendan Eich.

"I did the prototype for JavaScript in 10 days," Eich said in a history of JavaScript talk in 2010.

It arrived in Netscape Navigator 2.0, the dominant browser of the day, and has steadily spread in sophistication and popularity since. Its standardization, under the trademark-free name ECMAscript, has ensured many more than Netscape and its Mozilla descendant get a say in its development.

Many expected Java to be the language that added interactivity to the Web, but JavaScript instead won that place.

Now, despite plenty of rough patches, JavaScript is shouldering ever-heavier burdens.

"In 1998, a complex JavaScript application was a few dozen lines of code. By 2008, leading-edge Web applications like Hotmail, Gmail, and CNN.com included hundreds of thousands of lines of JavaScript," said the Microsoft JavaScript team members, Shanku Niyogi, Amanda Silver, John Montgomery, Luke Hoban, and Steve Lucco. "Today, there are Web applications with a million lines of JavaScript. These Web applications look more and more like the applications we run on our desktops."

Type inference's JavaScript speedup

One potentially major change coming to JavaScript execution is taking place at Mozilla through a feature called type inference that's built into the upcoming Firefox 9. That version of Mozilla's browser is currently in beta testing, slated to arrive before by very early 2012.

Type inference gets to the heart of a fundamental divide between programming languages: the nature of variables that store information such as numbers or text. JavaScript is dynamically typed, which means that a variable can hold any sort of information. Traditional heavy-duty languages such as C or Java, though, use statically typed variables whose nature must be declared in advance by the programmer.

Dynamic typing adds flexibility, but it slows down program execution. And one of Dart's high-profile features is that it supported static typing.

Dynamic typing is slower because a browser element called the just-in-time (JIT) compiler--which converts a programmer's JavaScript into the instructions a computer understands--must account for all the possible types a variable could be, said Brian Hackett, the lead type inference programmer, in a blog post. (For a lot more detail, check Mozilla's draft type inference paper (PDF).) Mozilla's hybrid type inference technology works by combining an analysis of JavaScript before it runs with further information gathered as the program runs.

One person who has high hopes for type inference is Paul Bakaus, CTO of Zynga Germany, which builds browser-based games.

"One thing I was looking forward to looking at Dart was static types. If you have static typing in JavaScript, you could really drive performance," Backaus said. "Once you figure that out, there's not so much difference between typed languages like C or C++."

And the performance is looking good, said Dave Mandelin, a Firefox programmer working on the Firefox's JaegerMonkey JavaScript engine. "JM+TI [JaegerMonkey and type inference] is looking good and on track for shipping with Fx9, with nice speedups pretty much across the board," he said in a blog post yesterday.

ECMAscript improvements

Microsoft has its own ideas for JavaScript--ideas that call for changes to the language, not just to how its browser runs it. Specifically, Microsoft promoted several new features at an ECMAscript standards meeting last week, the company said.

The features would build several items into JavaScript's included library that programmers today must add on their own. Those items include a handful of mathematical and numeric operations, ways to process text, and globalization technology to more easily handle different currencies and date formats.

In addition, Microsoft offered prototype software at its HTML5 Labs site that lets people try the technology.

"As the Web transitions from Web sites to Web apps, and as Web developers build new experiences in HTML5, we know that JavaScript will also need to make this transition without compromising its simplicity, flexibility, or performance," the Microsoft JavaScript team members said. And without mentioning Dart directly, they called for evolution rather than revolution: "An approach that enables broad, incremental adoption by the Web developer community has the highest chance of success."

Taking out the garbage

Even if Dart were to take off tomorrow, there still is an endless amount of JavaScript on the Web, so running it fast is important for Google's "build a faster Web ambition. On top of that, another faction within Google remains committed to JavaScript and its next-generation "Harmony" changes.

For those reasons, JavaScript performance is a top priority in the Chrome browser. Google has been locked in a benchmark battle with IE, Safari, Opera, and Firefox for years, but now it's working on another JavaScript performance improvement: consistent performance.

To that end, Google announced that the developer-channel version of Chrome now includes a feature called incremental garbage collection in its V8 JavaScript engine. It's designed to keep software responsive.

"V8's new GC [garbage collection] reduces pause times dramatically while maintaining great peak performance and memory use," programmers Vyacheslav Egorov and Erik Corry said in a blog post. "The new GC in Chrome improves interactive performance and opens up new possibilities for the interactive Web."

Garbage collection periodically frees up memory that a program claimed but didn't release, a very useful technology. But that process can hang up a computer while memory is tidied up. Incremental garbage collection breaks the process up into steps to reduce the pauses.

Google measured its success with one of its V8 benchmark tests of JavaScript performance. "In our testing the maximum time to render a frame including pause time is reduced from 272 milliseconds to 50 milliseconds," the programmers said.

Good interactive performance is harder to achieve with larger JavaScript programs, because a larger amount of memory must be swept.

Mozilla also is working on incremental garbage collection. "This stuff is hard, and we don't know how much tuning work there will be, but we're currently targeting IGC landing for Firefox 11," Mandelin said.

Fiddling with the JavaScript engine is difficult but has paid performance dividends for all the browser makers--and for developers, too. Dart will have to offer very compelling benefits to dislodge the established language of the Web.

Updated 10:57 a.m. PT to note that Firefox 9 is due by early 2012.