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

TimeoutOverflowWarning leading to performance issue #40

Closed
RobinBol opened this issue Aug 25, 2023 · 0 comments
Closed

TimeoutOverflowWarning leading to performance issue #40

RobinBol opened this issue Aug 25, 2023 · 0 comments

Comments

@RobinBol
Copy link

RobinBol commented Aug 25, 2023

When using this module to throttle an often called method I noticed that after a while a TimeoutOverflowWarning would occur:

(node:25711) TimeoutOverflowWarning: 2446812003 does not fit into a 32-bit signed integer.
Timeout duration was set to 1.

It can easily be reproduced using the following script which forces the overflow to occur after about 40 seconds. The problem is that the getDelay method keeps returing a larger timeout value on every call. As it is never reset it will eventually become too large to fit in a 32-bit integer. The setTimeout will default to every 1ms which has a negative impact on performance.

import PThrottle from "p-throttle";

const throttle = PThrottle({
  limit: 1,
  interval: 60000,
  strict: true,
});

const throttled = throttle(() => {
  return true;
});

(async () => {
  setInterval(async () => {
    throttled();
  }, 1);
})();

For now I've switched to lodash.throttle which does not suffer from this issue, but wanted to let you know anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant