I have a web application polls the server every 1 second for data to update its display. I see a gradual (over night) increase of CPU usage of the browser from 6% to 30% with no app interaction or change in behavior.
The problem is easily reproduced with this code running on Chrome, where I reduced the polling interval to 100ms to get a more noticeable effect:
<html>
<body>
<script>
var i = 0;
var xhr = new XMLHttpRequest();
xhr.onload = function() {
console.log("response", i++);
setTimeout(send, 100);
}
function send() {
xhr.open("GET", "/", true);
xhr.send();
}
send();
</script>
This code can easily be run on any web server like
python -m SimpleHTTPServer 8888
With this example CPU usage increases very fast for no apparent reason. I do no processing and use setTimeout and not setInterval so I never have overlapping requests.
I'm testing with Chrome (and Safari) and still see a very fast increase in CPU usage. Any ideas why?