Cloth simulations in Javascript, optimized for asm.js

Subject: General Tech, Mobile | May 4, 2013 - 03:47 PM |
Tagged: mozilla, javascript, firefox, asm.js

Web browsers are getting really good at being general-purpose application platforms.

You can write most applications in web standards if you are willing to give up some level of performance for the gained ubiquity. HTML5, Javascript, and CSS are very full featured; WebGL and WebCL extend functionality by backing apps with surprising GPU horsepower; WebAPIs such as gamepad, telephony, and accelerometer support also keep advanced hardware-specific features open to web developers.

View Full Size

I can see the web developers drooling already.

But even though performance lags behind reasonable native environments, the divide is rapidly shrinking. Many applications have reached or exceeded the saturation of useful performance at the same time as browser developers narrow the gap between native performance and themselves.

Javascript is often, simply, good enough.

Mozilla has recently added support for the draft asm.js in their Aurora prerelease channel for Firefox. The specification is designed to permit a subset of Javascript to be flagged for optimization in compatible browsers but otherwise execute as normal everywhere else. It is also possible to compile more native code into Javascript if you can afford the ever-decreasing performance hit. Early implementations of asm.js execute code compiled from C within half of native performance.

View Full Size

Because... pants.

According to David Herman of Mozilla, one of the lead authors of the ASM.js draft, the specification also allows for multithreading through web workers. Applications can take advantage of multiple hardware threads in this way, and potentially other methods as they continue development. I would expect this is especially relevant for mobile devices which tend to have relatively many cores considering their single threaded performance.

James Long of Mozilla compiled a cloth simulation into this Javascript subset. It will run in multiple browsers but will perform better in Aurora both in cloth precision and, as I have found, responsivity.

Check it out, imagine what you could be doing in your web browser in the near future.

Source: James Long
No comments posted yet.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote><p><br>
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.