Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setInterval/setTimeout causes a huge slowdown for setImmediate #17725

Closed
afrokick opened this issue Feb 26, 2025 · 0 comments · Fixed by #17901
Closed

setInterval/setTimeout causes a huge slowdown for setImmediate #17725

afrokick opened this issue Feb 26, 2025 · 0 comments · Fixed by #17901
Assignees
Labels
bug Something isn't working confirmed bug We can reproduce this issue

Comments

@afrokick
Copy link

afrokick commented Feb 26, 2025

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:

Image

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
@afrokick afrokick added bug Something isn't working needs triage labels Feb 26, 2025
@190n 190n added confirmed bug We can reproduce this issue and removed needs triage labels Feb 26, 2025
@190n 190n self-assigned this Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed bug We can reproduce this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants