It's called "function debouncing". Basically, you execute your stuff only once in a certain amount of time. A simple implementation would be:
var lastExecution;
addEventListener("deviceorientation", function (event) {
var now = Date.now();
if (now - lastExecution < 17) return; // ~60Hz
lastExecution = now;
...
}, false);
(Yes, lastExecution
is undefined at first. It's fine.)