Given:
window.setInterval(function () {
//test for a change in the window state and, if there has been one:
//make some changes
}, X); //repeat every X milliseconds
Is there a minimum acceptable value for X?
Some reading lead me to this interesting article, which suggests that, even if X = 1
, in reality the browser will run the interval only 10-15ms. But my question is more in regards to performance. I see two conflicting realities as X grows smaller:
- As X grows smaller, perceived "responsiveness" grows - a positive result.
- As X grows smaller, more system processing power is consumed - a negative result.
If system processing power was a non-issue, the obvious answer would be X = 1 because the moment the user changes the window, there is a more or less immediate response.
I know that the knee-jerk reaction is "well it depends how depleted system resources are, and how complicated the function is." But there must be some way to determine a reasonable lower bound. For example, is there a test suite I should be running on many system/browser combinations to know that X isn't so low that it is consuming to much processing power? Or is the answer "no value for x can possibly consume enough system resources to be noticeable," based on some fact about javascript intervals that I don't know?
Knowing the answer requires such specific details, a more refined question would be:
How does one go about determining the minimum value for X given any project/function combination? Is there a definitive method?