Closed
Description
What version of Bun is running?
1.2.4+fd9a5ea66
Also 1.1.25
What platform is your computer?
Darwin 23.6.0 arm64 arm
What steps can reproduce the bug?
Comment/uncomment line with setInterval
. Same for setTimeout
:
const waitTick = () => new Promise(setImmediate);
const runJob = async () => {
const st = performance.now();
await waitTick();
const et = performance.now() - st;
console.log(`${et.toFixed(3)}ms`);
};
const st = performance.now();
// setInterval(() => {}, 1000); // uncomment to see the issue
// setTimeout(() => {}, 1000); // uncomment to see the issue for X ms. After X ms the issue is gone
for (let i = 0; i < 1e3; i++) {
await runJob();
}
const et = performance.now() - st;
console.log(`finished in ${et.toFixed(3)}ms`);
export {};
What is the expected behavior?
The script should be executed in a few ms.
Expected result:
...
0.001ms
0.001ms
0.001ms
0.001ms
0.001ms
0.001ms
0.001ms
finished in 12.545ms
What do you see instead?
The script is being executed for a long period of time.
Actual result:
...
15.990ms
14.981ms
17.928ms
1.207ms
16.356ms
18.216ms
19.663ms
11.963ms
1.513ms
18.801ms
17.761ms
19.140ms
52.929ms
18.744ms
17.341ms
18.062ms
finished in 22252.256ms
~1700 times slower!
Additional information
I've checked Inspector and seems like the problem inside Partial GC
call:

NodeJS 20.10 result:
...
0.019ms
0.065ms
0.025ms
0.052ms
0.029ms
0.074ms
0.053ms
0.067ms
0.036ms
0.058ms
0.033ms
0.022ms
0.021ms
0.025ms
0.025ms
0.021ms
0.019ms
0.045ms
finished in 65.284ms