dart_eval icon indicating copy to clipboard operation
dart_eval copied to clipboard

Potential optimization: Use integers instead of Strings to look up methods

Open fzyzcjy opened this issue 2 years ago • 6 comments

For example, strings here: https://github.com/ethanblake4/dart_eval/blob/c5795f1e284a46e44d2f9c30b73eebc3b2787fc3/lib/src/eval/shared/stdlib/core/map.dart#L20 "length" can become (index) 2 etc.

This must be combined with the https://github.com/ethanblake4/dart_eval/issues/20 because it is so error-prone to manually assign numbers.

If doing https://github.com/ethanblake4/dart_eval/issues/65, this may be of less priority, since lookup happens in secondary isolate instead of the main isolate, so may not be the bottleneck.

fzyzcjy avatar Oct 20 '22 03:10 fzyzcjy

@fzyzcjy could you post the benchmarks that indicate that this sort of micro optimisation will have a positive improvement in performance?

maks avatar Oct 20 '22 03:10 maks

@maks These are just potential optimizations :) But we all know, strings are bigger than integers, so storage will be bigger and cpu will be slower. Yes it is a question how much it improves, so we may need to check it before implementing it.

fzyzcjy avatar Oct 20 '22 03:10 fzyzcjy

Looking up functions/properties by index is already done for classes defined inside of dart_eval when the concrete type is known. What you're talking about though, if I'm getting this correctly, is actually a sort of global string hash for function/field names? I'm not too sure that would work since you'd have to allocate large arrays for each object and populate all the missing values with null... or maybe I'm not understanding this right. Or maybe there's some way we can reuse indices by checking for collisions... the problem is that you can implements any class in Dart so I don't really know if that's possible.

ethanblake4 avatar Oct 20 '22 05:10 ethanblake4

Well I mean, at least, case 'length' becomes case 2. The "2" is generated by the compiler instead of "length" whenever it sees String.length.

fzyzcjy avatar Oct 20 '22 05:10 fzyzcjy

Oh, I see. So it's not an array lookup but just changing the Map key. That would work but probably very minor performance improvement.

ethanblake4 avatar Oct 20 '22 05:10 ethanblake4

At least bytecode size may be smaller.

Anyway this is just "potential" optimization :)

fzyzcjy avatar Oct 20 '22 05:10 fzyzcjy