devicescript icon indicating copy to clipboard operation
devicescript copied to clipboard

Infinite loop in Array.sort

Open louisvangeldrop opened this issue 1 year ago • 5 comments

  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)

louisvangeldrop avatar Sep 17 '23 10:09 louisvangeldrop

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.

mmoskal avatar Nov 01 '23 16:11 mmoskal

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

louisvangeldrop avatar Nov 01 '23 21:11 louisvangeldrop

Not currently.

mmoskal avatar Nov 01 '23 22:11 mmoskal

@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. :)

IvanMtze avatar Dec 22 '23 17:12 IvanMtze

It would be most welcome!

mmoskal avatar Dec 22 '23 18:12 mmoskal