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

dangling requestAnimationFrame loop causes high CPU usage, even after it is destroyed #4

Open
paulovieira opened this issue Nov 11, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@paulovieira
Copy link

Hello and congratulations for this nice and sophisticated library!

I'm using a simple flip countdown (using one of the examples from pqina/flip). The countdown is created and destroyed dynamically. However after being destroyed (which is done with tickInstance.destroy()) I noticed an unusual high CPU usage.

After some investigation I found the problem: in the presentTick function in https://github.com/pqina/tick/blob/master/src/core/js/utils.js, draw is called recursively using requestAnimationFrame. This loop doesn't stop, even after the tick instance is destroyed.

I solved the problem with a quick and dirty monkey-patch:

  1. after calling tickInstance.destroy(), set tickInstance._IS_DESTROYED = true;
  2. in presentTick, check if the instance is destroyed before calling requestAnimationFrame, that is:
	var draw = function draw() {
		instance.baseDefinition.presenter.draw();

		if (instance._IS_DESTROYED) { return; }

		requestAnimationFrame(draw);
	};

The CPU is now back to 0 as expected, so I'm pretty sure the problem was here.

Hopefully this problem can be solved in a future release.

Thanks for your time.

@rikschennink rikschennink added the enhancement New feature or request label Nov 12, 2021
@rikschennink rikschennink added bug Something isn't working and removed enhancement New feature or request labels Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants