Advertisement
Promo

Become a member of the ZDNet UK community

Rupert Goodwins

View blog's RSS Feed

Mixed Signals

Any sufficiently advanced information is indistinguishable from noise

Sunday 24 August 2008, 3:57 PM

JavaScript - a Flash competitor?

Posted by Rupert Goodwins

Open source software has its problems when it's trying to keep up with proprietary software, but when it does what it's good at – creating ideas and developing them very quickly in public – it can be revolutionary. Take TraceMonkey, a newly announced Mozilla-based project that speeds up JavaScript execution dramatically and thus speeds up the Web. Just sixty days old from the start of development, it's doing things that any proprietary company would be proud to present as the end result of intensive, expensive research. And it's doing them in the open, so we can peek inside and find out what's going on.

In the beginning is the word – in this case, JavaScript. JavaScript glues a lot of the Web 2.0 world together, but it's no speed demon. It's designed as an interpreted language; the server sends Javascript to a client, and that client has to parse and translate each line into machine code before any useful work is done. That's cool – it means that JavaScript programs don't have to worry about the details of a client system as long as it conforms to the language specification.

But fast code needs to be compiled, where the translation work gets done ahead of time and the machine code is loaded and run whenever needed. If you can save the machine code because you know you'll need it again, this is very useful. And modern compilers don't just translate, they also analyse how the program's structured and work out the most efficient way to produce the machine code depending on what's actually happening. This optimisation is the most difficult part of compiler technology to get right, but the one with the most potential for speeding things up.

There are JavaScript compilers, but the basic idea doesn't fit very well with Web use – who wants to sit around after a page loads while an entire program is translated before anything happens? It's also not very useful to keep copies of the translated code, given the huge number of different pages a web user will visit and the relative rarity of revisits to unchanged pages.

So a third way is being explored – Just In Time compilers, or JITs. These are a cross between an interpreter and a compiler: they interpret each line of a program as it is executed for the first time, but keep a machine code representation. Then, if the program goes back to that line (most programs have loops and program branches that ensure multiple execution of portions of themselves), the compiler knows to refer to the translation it prepared earlier.

That combines the immediacy of interpretation and some of the potential speed-up of compilation, and you get code re-execution without having to maintain a huge database of pages. However, it's not much good for optimisation; if you translate everything when you encounter it for the first time, you've got little chance of understanding enough of what's going to happen next. And as there's a lot you don't know while you're compiling, you have to create and keep lots of code that can cope with different possibilities. That takes up a lot of time and memory.

Enter the TraceMonkey. This is the latest JIT for JavaScript, and it's showing some truly awesome increases in speed. As the name suggests, it traces the code it's running, effectively analysing the program on the fly. In particular, it spots loops and program branches, areas where parts of the program are repeatedly run – and then traces through them, working out which paths are going to be most taken. Then it compiles those, taking the opportunity to properly optimise each path it's working on – it's got enough context by then. Loops are miniature programs in their own right, complex enough to be worth working on, small enough to make the task manageable.

Various interesting things follow. Why bother compiling stuff that's infrequently run? You can concentrate on the optimisable bits, and leave the interpreter to cope with the rest. One key observation is that nearly all time spent in JavaScript programs is in loops – there's just not very much linear, run-once code in the sort of Web tasks JavaScript does. And proper, focussed optimisation generates fast, lean results that work well in limited conditions, such as mobile phones. TraceMonkey is part of FireFox 3.1, albeit turned off by default, and thus simultaneously available in x86 and ARM. That's interesting in its own right, given Intel's insistence that ARM Web technology lags x86 by a year or two.

You can read a lot more about TraceMonkey, and tracing compiler technology in general, by following some of the links from the initial announcement. But the stuff you need to know is that in benchmarks, TraceMonkey is delivering up to 30 times speed improvements over the norm – with most useful stuff running between two and eight times faster. It's not finished by any means (what do you expect from a three month old?), and when you're writing compilers the devil really is hunkering down in the sulphurous details. Expect bugs for a while yet.

Yet the implications are enormous. TraceMonkey fans are saying that these ideas can make JavaScript a potential rival to Flash, allowing complex Web-based applications and services to be delivered in a completely open framework. On the evidence so far, they could well be right.

(To play with the TraceMonkey, download FireFox 3.1, do about:config and toggle javascript.options.jit.content to 1.)

Comments on this post

Tezzer

Doncha just love FOSS :)

Posted by Tezzer on Aug 24, 2008 7:02 PM

ator1940

Amazing how fast things happen in open source compared to proprietary

Posted by ator1940 on Aug 25, 2008 1:40 PM

Rupert Goodwins

It's also amazing how slowly things happen - or perhaps not. FOSS is excellent at clever things, where smart coders can get hold of a bright idea and push it into the limelight in double-quick time. It's terrible, often, at usability and other 'dull' stuff that really matters.

I think this is where Apple does well. It doesn't have Microsoft's antipathy to open source, so it can help itself freely to huge amounts of good stuff, but it does have a corporate focus on usability. So, it can spend a lot more of its resources on making things 'just work' in a an attractive fashion. Microsoft seems stuck with battling its own history, trying to rebuild the basics behind the factory walls and losing that battle more and more each time - and nobody else can help, even if they wanted to.

Updated by Rupert Goodwins on Aug 26, 2008 8:18 AM

afnan

This comment has been deleted at the users request

Updated by afnan on Aug 26, 2008 8:19 AM

jandler

Microsoft *is* battling their own history but for reason that most of you do not seem to understand or do not want to understand. Microsoft has been and still is the provider of the most dominant developments platforms in the history of software development. As such, people expect that everything that they built and will build must be backward compatible with everything else, which is a humongous task. They cannot simply wake up one day and introduce any new technology that breaks any previous one; something that many of their competitors are doing. For instance, Apple only needs to make something that “just work” for Apple. Microsoft needs to make something that “just work” for everything else.

Updated by jandler on Aug 27, 2008 8:19 AM

Rupert Goodwins

Microsoft's devotion to legacy code has been a major component of its operating systems since the days of MS-DOS. I doubt anyone's missed that!

That's a strategy MIcrosoft has chosen to adopt, but it's not the only way. Apple has now managed two processor family transitions on the Mac - 68K->PPC->x86 - without breaking its market. Vista would have been a lot smarter had it had, say, an XP-compatible virtual mode to run legacy software and a much cleaner, more secure, OS outside with lots of XP management chops and a clear migration path. At the time Vista was being planned - and certainly at the time the development process was being rebooted intermally - MS would have known that the vast preponderance of new processors during Vista's lifetime were going to have hardware virtualisation: even if not, aspects of this can be implemented in software (as Apple effectively did).

Not saying that this would have been an easy strategy, but it would have shown some evidence of long-term strategic thinking beyond 'fiddle with the OS until it only breaks a little', as well as offering many more options for the future. As it is, virtual XP runs just as well under host Linux, Unix or OS X as it does under host Vista - a dangerous state of affairs to which MS' only competitive response has been to try and get XP off the market.

Way to go.



Updated by Rupert Goodwins on Aug 27, 2008 9:14 AM

J.A. Watson

@jandler - Unfortunately, "breaking" things that worked in previous releases is exactly what Microsoft did with Vista, and it is one of the biggest things that users have been screaming about. The worst example is device drivers, of course, but there are plenty of others - programs, applications, utilities that don't work, menus that have been gratuitously changed, and so on.

My take on the current Microsoft "Vista Really Isn't So Bad" advertising campaign is that now that they have removed XP from the market, they are trying to get people to forget about how much Vista broke things. They claim they have "fixed" most of the incompatibilities, but from my perspective I see very little difference - my BJC-55 printer's scan head still won't work with Vista, nor will my HP Scanjet 4670, or my Linksys SRX400 wireless adapters, or the Lantronix Device Installer software...

jw

Updated by J.A. Watson on Aug 27, 2008 11:16 AM

Xwindowsjunkie

Vista was thought by MS management to be the "conservative" or "safe" decision for the company's future. I've seen the same "pointy-haired" boss management style before. Instead of getting rid of legacy issues by engineering a new way to do things, they went with what they already had going. I have railed against virtualization here on these pages before and I'll probably do it again. Its obvivious though that Vista should have been Virtual instead.

Support for legacy could have been in sandboxes tailored for each old OS. Windows already runs MSDOS in a NTVDM, take it to the next step and separate it as completely as possible from the host process. Think of the sandboxes as insular plug-ins that operate in VPC modules. The host OS would be the simplest and tightest code possible to operate the plugins. No direct user interface to the kernel running completely isolated. You want to play a DVD movie, you have a VPC module to play it on the DVD drive.

Updated by Xwindowsjunkie on Aug 27, 2008 3:24 PM

Rupert Goodwins

The more I think about it, the more sense it makes for the Next Big OS Thing (NBOST) to be heavily virtual. As Microsoft knows only too well, though, decoupling your OS from the hardware only makes sense if your business model doesn't rely on a licencing system that tries very hard to stick OS to hardware with limpet resilience. Vista even deactivates your OS if you make too many changes to your hardware (way to go x 2) - this is not a company at ease with abstraction.

Such matters aren't of the slightest interest to FOSS types, for whom the basic mantra 'it's your software, do with it what you like' is utterly at home with any and all hardware innovations.

Updated by Rupert Goodwins on Aug 27, 2008 4:50 PM

Xwindowsjunkie

I'm sorry this has gotten off subject but perhaps its not that far off. Although I think a lot of "virtualisation" is still snake-oil, there are some benefits to be gained from it.

Microsoft if they want to maintain legacy support (and I actually think its a good idea) they can use the sandbox or Virtual PC model and stick the legacy OS and programs into a virtual PC module or window.

They could even announce before-hand which previous versions of Windows or other x86 OSes they are willing to support. I would hope that would include Win2K and XP Pro. Vista I couldn't care less about but from a marketing standpoint, Microsoft will have to offer support for their unfortunate mistake. The VPC module or window could have security rules and code imposed on it to prevent violations of the host kernel. That would improve the security mode of everything run on the system.

I suppose that access to the hard drive from within the kernel will be necessary. Security on the system partition can be encrypted though so that can be actually a benefit. Other areas of the hard drive can be mapped with permission sets

Beyond that Microsoft could offer an API or a "VAPI" so that others could write applications or OS modules to run in the VAPI windows' boxes. There might even be programmers willing to offer code to support Windows versions MS doesn't want to support.

One other thing it would allow is for Microsoft to go into a mode whereby they could update and or replace sections of their OS without having to do a wholesale complete revision every 3, 4 or 7(!) years. It would also justify their desire for a subscription business model. They could offer an annual subscription for their OS instead of a car down payment for a operating system "lease-NOT-to-own".

I have spent a lot of time running Virtual PC 2007 at work and although it requires considerable CPU power to run without bogging down the system it does offer some benefits. I don't think its the answer but it is pointing in the right direction.

Having a publicly published specification could allow their customers or others to build applications that do not infringe on MS copyrights or patents while still offering shareware or freeware applications to flourish. It might even allow Linux applications to operate in the VPC window.

Microsoft is going to have to learn that an operating system does not have to operate everything plugged into or installed on the box. It would make more sense to have an operating system kernel be as small and as fast as possible. Then put all of the hardware drivers into the VPC module and allow access to the hardware via permissions set in the kernel. Think of it as a 2-way firewall for hardware access.

Has there been any work towards a standard model of a virtual PC that could be supported by all the various OS vendors or non-vendors? How much different would that be from a specification for the hardware found in an x86 PC? I suppose the answer is found in the response to: "How do you isolate the hardware from the VPC window and an unauthorized user?"

I know that I would like to split the system partition, the USB port, the CDROM drive and the floppy interface away from the user's access at least for my corporate work designs. It can also be a security benefit for kiosks and other publicly located systems. Microsoft if they are willing to think outside of their self-inflicted box can really offer something new and innovative.

Updated by Xwindowsjunkie on Sep 1, 2008 10:29 AM

jandler

@J.A. Watson
MS did the best they can to keep as much things working as possible. If you can quote personal experience as proof then I guess I can quote mine as well as those are of family and friends. All of which devices worked perfectly fine with Vista from day 1.

Will everything be 100% working with everything else? Never. And as for the device drivers. Well you can blame the device manufactors. Beta version of Vista has been delivered to them for earlier that Vista RTM. I guess they just wanted you to buy new stuff. That's business.

Posted by jandler on Nov 8, 2008 4:00 AM

Rupert Goodwins
  • Rupert Goodwins
  • Location, location, location
  • Member since: October 2006
ZDNet Staff

My Blog Archive


Contacts' Latest Discussions

Number of Tracked Discussions: 3,124

J.A. Watson J.A. Watson

The Shine is off the Polish

Monday 9 November 2009, 1:48 PM

2 comments
ator1940 ator1940

"polished Moblin"

Monday 9 November 2009, 1:32 PM

2 comments
J.A. Watson J.A. Watson

Using Windows Is Like...

Sunday 8 November 2009, 8:38 PM

6 comments
J.A. Watson J.A. Watson

Using Windows Is Like...

Sunday 8 November 2009, 6:06 PM

6 comments

Contacts' Latest Blogs

Number of Contacts Blogs: 18


Skip Sub Navigation Links to CNET Brand Links

Help

Become part of the ZDNet community.

Newsletters