Improve loop protection warning for slow loops that are not infinite

Description

The p5.js Web Editor’s loop protection can report an infinite loop when a loop is simply expensive to execute.

For example, this p5.js issue was initially reported as an infinite loop:

After profiling it, the loop itself terminates normally. The warning is triggered because rendering the WebGL spline geometry takes long enough to exceed the editor’s loop protection threshold.

A similar case was reported on the Processing forum:

In both cases, the current message:

Error: Multiple infinite loops detected. Stopping execution.

makes it sound like the editor has determined that the user’s code contains an actual infinite loop, when it may instead just be a slow loop.

Possible improvement

Would it make sense to update the warning to make this distinction clearer?

For example:

This loop is taking a long time to execute and may be infinite. Execution has been stopped.

or something similar that doesn’t state conclusively that an infinite loop was detected.

I’m happy to work on this if we agree on the desired behaviour/wording.

There is ticket about it on p5.js GitHub #9026 I investigated with @davepagurek

1 Like