powerlang / egg

Egg Smalltalk
MIT License
13 stars 2 forks source link

Implement an ast inliner for the JS VM #2

Open melkyades opened 1 year ago

melkyades commented 1 year ago

Our interpreter is implemented using nice OO practices, but V8 doesn't optimize it well. For example:

SInstVarBinding>>valueWithin: anEvaluationContext
    ^ anEvaluationContext instanceVarAt: index

reads an ivar for the receiver in the evaluation context, the evaluation context delegates that to the runtime:

EvaluationContext>>instanceVarAt: index
    ^ system instanceVarOf: self self at: index

then:

PowertalkLMR>>instanceVarOf: receiver at: anInteger
    ^ receiver slotAt: anInteger

and finally:

slotAt: index
    ^ slots at: index

Instead of generating vanilla js, we can use a type inferencer (maybe with some manual annotations) that helps V8 by inlining every involved method, generating something like this:

SInstVarBinding>>valueWithin: anEvaluationContext
    ^ anEvaluationContext self at: index