microsoft / devicescript

TypeScript for Tiny IoT Devices (ESP32, RP2040, ...)
https://microsoft.github.io/devicescript/
MIT License
3.24k stars 112 forks source link

Infinite loop in Array.sort #624

Open louisvangeldrop opened 9 months ago

louisvangeldrop commented 9 months ago
  1. Create an arbitrary Array of numbers with length>100
  2. myArray.sort() results in:
  3. Exception: InfiniteLoop VM> at sort [as F9_pc84] (node_modules\@devicescript\core\src\array.ts:206:13) VM> at main [as F0_pc37] (src\main.ts:90:1)
mmoskal commented 8 months ago

I suspect it just runs for too long - the algorithm is quadratic - PRs are welcome!

We limit execution to DEVS_MAX_STEPS (128k) opcodes before you need to yield.

louisvangeldrop commented 8 months ago

Is the DEVS_MAX_STEPS a parameter that one can define during runtime?

mmoskal commented 8 months ago

Not currently.

IvanMtze commented 6 months ago

@mmoskal Have you consider using timsort algorithm instead of the current implementation? I believe is what V8 uses. I can work on this if that is a better approach than the code has for now. :)

mmoskal commented 6 months ago

It would be most welcome!