devicescript
devicescript copied to clipboard
Infinite loop in Array.sort
- Create an arbitrary Array of numbers with length>100
- myArray.sort() results in:
- 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)
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.
Is the DEVS_MAX_STEPS a parameter that one can define during runtime?
Not currently.
@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. :)
It would be most welcome!