What kind of code is suitable for partial evaluation? I would imagine anything that uses late binding or monkey patching would be out, and also anything that dynamically dispatches via global state (like calling methods on global variables).
So I'm quite surprised / incredulous that Javascript would work...
The GraalVM family of language implementations are all based on partial evaluation. You can get really good performance out of dynamic languages using these techniques if you can reliably detect when things have been invalidated.
Depending on the context that might be, “Somebody touched a prototype,” or you might separate parts of the process of method lookup and evaluation and try to specialise on the resolved method.
Working on TruffleRuby was one of the most fun things I’ve done in my career, some things that are normally the hardest to optimise were beautifully simple.
You can not partially evaluate potentially un-pure constructs like that to effectively treat them as part of the external world (the input). That's how I/O functions would be treated. You'd have to, anyway; you can't partially evaluate any code not explicitly given to the partial evaluator.
Calling through pointer cannot be collapsed unless you manage to provably evaluate all mutations of said pointer at compile time. But only if the pointer can truly hold an arbitrary value.
If you can prove that are e.g. two distinct values the pointer can point to you can specialize the rest of the program for both of those instead and branch into correct "world" instead of keeping calling through the pointer. This obviously leads to an explosion of combinations if done eagerly.
With some good heuristics, if you can e.g. spot program selecting a different SIMD backend and then just keeps using it, specializing for each variant would be a huge boost for performance.
Sometimes you don't have enough information at the compile time. E.g. you do not know how hot the pointer you'd be calling through really is. Could be once at startup. Could be 100k times per second. If you run the program interpreted (or instrumented) on typical workload, you can determine how hot the loops actually are and thus use this profile to guide your specializations.
This allows you to see through e.g. the monkey patching for your typical workload. Profile says the program runs for a while using one pointer but then switches to another pointer and then heavily uses that. So you retain the call-through-the-pointer situation but also specialize for the monkey-patched situation that actually carries most of the workload and reap the performance benefits.
hmry | 9 hours ago
What kind of code is suitable for partial evaluation? I would imagine anything that uses late binding or monkey patching would be out, and also anything that dynamically dispatches via global state (like calling methods on global variables).
So I'm quite surprised / incredulous that Javascript would work...
aardvark179 | 4 hours ago
The GraalVM family of language implementations are all based on partial evaluation. You can get really good performance out of dynamic languages using these techniques if you can reliably detect when things have been invalidated.
Depending on the context that might be, “Somebody touched a prototype,” or you might separate parts of the process of method lookup and evaluation and try to specialise on the resolved method.
Working on TruffleRuby was one of the most fun things I’ve done in my career, some things that are normally the hardest to optimise were beautifully simple.
tentacloids | 3 hours ago
You can not partially evaluate potentially un-pure constructs like that to effectively treat them as part of the external world (the input). That's how I/O functions would be treated. You'd have to, anyway; you can't partially evaluate any code not explicitly given to the partial evaluator.
mordae | an hour ago
Calling through pointer cannot be collapsed unless you manage to provably evaluate all mutations of said pointer at compile time. But only if the pointer can truly hold an arbitrary value.
If you can prove that are e.g. two distinct values the pointer can point to you can specialize the rest of the program for both of those instead and branch into correct "world" instead of keeping calling through the pointer. This obviously leads to an explosion of combinations if done eagerly.
With some good heuristics, if you can e.g. spot program selecting a different SIMD backend and then just keeps using it, specializing for each variant would be a huge boost for performance.
Sometimes you don't have enough information at the compile time. E.g. you do not know how hot the pointer you'd be calling through really is. Could be once at startup. Could be 100k times per second. If you run the program interpreted (or instrumented) on typical workload, you can determine how hot the loops actually are and thus use this profile to guide your specializations.
This allows you to see through e.g. the monkey patching for your typical workload. Profile says the program runs for a while using one pointer but then switches to another pointer and then heavily uses that. So you retain the call-through-the-pointer situation but also specialize for the monkey-patched situation that actually carries most of the workload and reap the performance benefits.