You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
An async WHILE loop waits for a timer before each iteration #2979
An async WHILE loop waits for a setTimeout(..., 0) before each iteration. This makes the loop much slower than the sync loop.
constsql='DECLARE @i INT; SET @i = 0; WHILE @i < 300 SET @i = @i + 1';alasql(sql);// 10 msawaitalasql.promise(sql);// 388 ms in Node 24
Browsers make nested timers wait at least 4 ms. In a browser, 300 iterations thus take at least 1.2 s, and 10 000 iterations take at least 40 s.
The timer is in yy.While.prototype.execute in src/statements/while.js. It gives the event loop a turn after each iteration. That is useful, but a timer is the slowest way to do it.
Proposal
Use a faster yield. Use scheduler.yield() if the browser has it. If not, use a MessageChannel in the browser and setImmediate in Node. Use setTimeout(0) only as the last choice.
Yield only when 16 ms have gone by since the last yield, and not after each iteration.
The async loop must continue to give the event loop a turn by itself. Users must not have to add a yield to the loop body.
Activity
Improve async WHILE loop performance to close AlaSQL#2979 (AlaSQL#2982)