Adding SIMD Vectorization to JavaScript Share your comment!

Posted on by Jeff Cogswell, Slashdot Media Contributing Editor

Some engineers at Intel have added SIMD capabilities to JavaScript. In the first of this two-part series, Jeff Cogswell talks about the rationale behind this.

Some engineers at Intel have been working on a project that sounds very interesting: Adding SIMD vectorization to JavaScript. Although their product isn’t available yet, they have made some sample source code available. In this blog, I’m going to talk about why this is such an important project. Then next time we’ll look at some of the sample code and see if we can figure out what they’re doing.

 When the web was created some 20 years ago, it consisted just of static pages. Shortly after that, forms were added, but there wasn’t much interactivity beyond that. Now fast forward to 2014, and we see a radically different web; we don’t see just web pages, but we see entire software applications running in the web browser. Google’s Gmail is a great example of a web application, as is Facebook. You don’t browse through pages on these two sites. Instead, you interact through a GUI that runs in the browser. The GUI is written in JavaScript, because that’s the language that the browser understands.

 I hear a lot of criticism about JavaScript, and some of it is justified and some of it is perhaps more due to a lack of understanding of it. Love it or hate it, JavaScript is the most common language we use for developing web applications. (There are some alternatives, such as CoffeeScript, but the code written in these languages is converted to JavaScript. The exception is Google’s Dart, but we’re a long way from having universal support for it.)

 Six years ago, I was doing a good amount of JavaScript coding and I found it cumbersome and slow. But in the last four years or so, the browser vendors have greatly sped it up through optimizations and just-in-time compilation. Further, libraries such as jQuery and Knockout.js (two of my favorites) have greatly simplified the work of writing browser applications. Then HTML5 came along, and the world has gotten even better with canvases, local storage, and more. While JavaScript is much faster than it used to be, it still has a lot of room for improvement. One such area is, of course, parallelization. Presently, JavaScript is not parallel. It uses an asynchronous model, but it’s only single-threaded.

 As parallel developers, we can all name two areas where JavaScript could be made parallel: multicore and vectorization. These are, of course, the two technologies we use most often for our parallel work.

 Intel engineers have been working to modify the open source JavaScript engines used by Chrome and Firefox to support SIMD vectorization. But they’re doing so by not modifying the JavaScript language itself. Thus, in order to access the new SIMD features, they’ve also written a library of JavaScript code.

 Think of how Intel Composer can generate C++ code that can detect what SIMD architecture is available, and automatically make use of it. That’s the same idea with this SIMD JavaScript library. Since the engineers aren’t changing the language, this SIMD library will attempt to use SIMD vectorization if available, and if not, the code will use traditional non-vectorized loops. That means you can write your JavaScript code that calls into the SIMD library, and the code will run whether SIMD is actually available or not.

 Conclusion

 This is a fantastic idea, as it will bring JavaScript one step closer to supporting near-native applications. We could also use multicore features as well, but that will come another day. Meanwhile, in the next blog I’m taking a look at the SIMD JavaScript library. Although the JavaScript runtime engine with SIMD capabilities isn’t available to us, we can at least look at the JavaScript code the Intel engineers are using and see how it works.