mozilla / pluotsorbet

[ARCHIVED] PluotSorbet is a J2ME-compatible virtual machine written in JavaScript.
GNU General Public License v2.0
238 stars 46 forks source link

Reduce the overhead of calling natives #335

Open marco-c opened 10 years ago

marco-c commented 10 years ago

Is it possible to reduce the native call overhead? There may be some steps in the invoke* bytecodes that we may skip in the native/override cases.

marco-c commented 10 years ago

@andreasgal

andreasgal commented 10 years ago

Method calls in general aren't very well optimized yet. Especially virtual and interface dispatch is kinda comically slow. I would measure what slows us down most right now before we do this though. Are you sure this is a big cost right now?

marco-c commented 10 years ago

Indeed I've noticed a big overhead with functions that override a virtual function. For example: 245ms 84260 com/sun/cldc/io/ResourceInputStream.read.()I On a phone: 14288ms 112518 com/sun/cldc/io/ResourceInputStream.read.()I

It's probably more worth improving method calls in general.

andreasgal commented 10 years ago

Yeah. We can implement a traditional virtual method table, or since we have JS and cheap hash tables we can implement a virtual method cache on the classInfo object. If you call method m on an object of class C and it triggers implementation n, then basically do C[m] = n and then check that first. That avoids walking the chain of classes in getMethod. The same works for interfaces.

andreasgal commented 10 years ago

(I would do a cache because most methods are never called, making VMTs large and sparsely used and we avoid regressing startup to create VMTs)

marco-c commented 10 years ago

I'm doing it in #337.