scratch-vm icon indicating copy to clipboard operation
scratch-vm copied to clipboard

Tuning request: List access

Open ArnoHue opened this issue 3 years ago • 12 comments

Performance-profiling the GoK Chess project at https://turbowarp.org/148769358 via Google dev tools, it shows that a significant amount of time is spent on list items access, mostly listGet() and listReplace(), which in turn invoke listIndex().

I noticed that there is special handling required for string-based index parameters like "first", "last", "random", and expect this to be a main cause. I am no JavaScript expert, but was wondering whether there might be an alternative, e.g. passing the index parameter straight through in JavaScript, and only if the item turns out to be undefined, trigger special handling for string parameters. Or alternatively, detect those string constants during parsing, and generate special JavaScript code to cover the string index cases. This still leaves out dynamically passed strings, but that scenario should be extremely seldom. I suppose a Visitor pattern implementation might not be an option due to weak typing?

ArnoHue avatar Oct 26 '22 17:10 ArnoHue

Long-term we want to rewrite the compiler to be able to reason about variable types much more effectively. Short-term I'll try to find some time over the next week or so to look for any low-hanging fruit to help your project

GarboMuffin avatar Nov 14 '22 07:11 GarboMuffin

Long-term we want to rewrite the compiler to be able to reason about variable types much more effectively. Short-term I'll try to find some time over the next week or so to look for any low-hanging fruit to help your project

You could include an additional feature in the "Turbowarp Blocks" extension where you can make variables that only support numbers, or you could make it so that the compiler checks to see if there is any way that the variable can become a string, and if there is a way it can become a string (like setting a variable to a string using the block or allowing the user to control the variable using the "ask ( ) and wait" block) and if not, then you can make the variable integer-only.

n-d-v avatar Aug 04 '23 12:08 n-d-v