On Mon, Jan 28, 2019 at 04:50:28PM -0800, Kris Maglione wrote:
Whatever else this whole process accomplishes, it will have the major side-effect of making our system JS code much more JIT-friendly, and in many cases, some orders of magnitude faster.

Since there's been some question about my "orders of magnitude" comment, I may as well explain:

To begin with, the weirdness of our JSM scopes makes a fair amount of our system code un-JITtable, which should be enough on its own. But even for code that we can JIT (which is still a lot of it), there's another problem: In order to make code fast, the JIT needs to be certain that it knows the location and type of every variable that it touches, and that those values can't change out-from-under it.

For code that deals with global variables and has weird scope chains, though, that's not really possible. There are scopes in-between the executing scope and the global scope that the JIT doesn't really understand, and can't really trust. So, in an ideal world, the following, for instance:

 for (let i = 0; i < typedArrayA.length; i++) {
   typedArrayC[i] = Math.floor(typedArrayA[i] / typedArrayB[i]);
 }

The Math.floor call can be inlined into pure assembly operations that take a few nanoseconds. The whole loop becomes pretty similar to the equivalent construct in C.

If we're in a JSM environment, though, the JIT can't trust the value of `Math` to stay the same from one iteration to the other. It has to walk the scope chain for every iteration, and do a hash lookup for the name `Math` in each scope, until it finds a match. Hash lookups are expensive. The same operation which took nanoseconds in an ideal world takes microseconds in our current JSM world. That's three orders of magnitude slower before we even take into account the memory we touch that's now taking up valuable L1 cache or register space, or the likelihood that we have to do a real JS function call rather than do some simple inline arithmetic.


This is probably more than most of you want to know, and less than the rest of you want to know, but it's been a long week for it being only a Monday night, so there you are.

-Kris
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to