dart_eval
dart_eval copied to clipboard
Potential optimization idea: Use another isolate (or multi isolate) to decode and prepare instructions as much as possible
Recall that, it is O(1) not O(N) to pass data back to main isolate, if the extra isolate send it via terminating message.
For example: from raw bytes to objects, including bridge methods etc. So that in main isolate we only need to call that (dynamic) function and done.
@fzyzcjy why do you expect using a separate Isolate will improve performance? Do you have some specific plan on how to parallelise the work dart_eval currently does and why do you expect the overhead of passing data to/from a background Isolate will not out weigh any improvement from multi-threading? Have you done any benchmarks for this?
@maks Hi, this is just an idea, but my logic is:
passing data to/from a background Isolate will not out weigh any improvement from multi-threading
Data pass from main to secondary, O(N): The raw bytes, say only 100KB (compressed), just downloaded from the backend server. IMHO memory-copy 100KB is quite fast. IIRC I did even pass 20MB big image to secondary isolate with O(N) copy and it was still not noticeable.
Work done in secondary:
a. decompress the bytes
b. decode into a list of ops, including finding the right method handler. so, for example, a operation may be "call String.subString", then the final Op should be a object constructed such as:
var that_decoded_op_should_be_like = Op((String s, int a, int b) => s.substring(a,b);
etc
Data pass from secondary to main: It is O(1), so no worries.
Using an isolate to decode the EVC bytecode file into the list of ops is something I'll probably do eventually, once EVC files are commonly large enough to cause jank when loading. (Also, EVC loading is really unoptimized right now generally, so there's probably some other things I'll change first before this)
var that_decoded_op_should_be_like = Op((String s, int a, int b) => s.substring(a,b);
Doing a JIT-like thing with the ops is really interesting, beyond just the potential of using an Isolate. I'm a little wary that it actually may not be faster given the closure though, so this definitely needs further investigation.