bobtato
bobtato

Reputation: 1229

Explicit control of JavaScript JIT?

I'm working on some code (for audio processing) that relies heavily on modern JavaScript optimization for performance. I dynamically generate JS methods to do a bunch of arithmetic on the contents of Int32Arrays, and I want these methods to run as fast as possible. The "magic" optimisation works pretty well, and I have some idea of how to help it along, but I wonder if there are ways to improve on that.

It occurs to me that it would be good if I had some way to tell the JavaScript engine "this method will always run very hot, and the types of its arguments should never change". That way, (1) the compiler could potentially work sooner and better, and (2) if the type of an argument is wrong, or optimization fails for some other reason, I can get an exception instead of silently falling back to the interpreter.

Does anyone know of any standards or initiatives of this kind? Or failing that, are there profiling tools to see exactly how my code is or isn't being optimised (in Chrome, Firefox and Safari)?


Update

Regarding asm.js-- I hadn't heard of that-- it sounds cool, and it has a lot of tricks that are useful to read about for this kind of work.

As I understand it, asm.js itself is just a convention for writing highly-optimizable JavaScript, rather than a new specification for JS engines. However, it does define a way to label compliant sections of code (by putting the line "use asm"; at the beginning of a method), with the intent that future JS engines will respond to this and use a special Ahead-of-Time (AOT) compiler on those sections, reporting errors to the console if the code doesn't meet the stricter standards regarding type safety etc.

AFAICT Mozilla have started on an AOT compiler, and Google are talking seriously about it for V8. I can't find anything about plans for JavaScriptCore, and I wouldn't hold my breath regarding IE.

But it does kind of answer my question, I guess-- if I generate code that validates with asm.js now, there's no downside, and in browsers of the future I might get a performance bump.

Upvotes: 2

Views: 115

Answers (1)

DaoWen
DaoWen

Reputation: 33019

Chrome's V8 engine has a bunch of options for this type of debugging. I think you'll find this blog post useful:

Optimizing for V8 - Introduction

(It's actually a whole series of posts, so you can get into more advanced options if you keep reading.)

Upvotes: 1

Related Questions