Javascript setTimeout performance vs manual check -
i'm writing webgl game , curious if better performance wise implement game's events checking if should occur @ every update of requestanimationframe (using date.now()) or setting timeouts (using settimeout()).
note events 100ms apart.
my major concern settimeout not waste cpu when idle (waiting next event) , if check @ every update ill doing computations wouldn't happen if using settimeout
if need events, create events , use eventlisteners.
if need check @ every call of raf condition has changed perform action, checks in raf loop.
note : don't need , should avoid creating new date object @ each call ; there timestamp passed argument of requested function through raf, use this.
function update(timestamp){...}; requestanimationframe(update); using settimeout @ high rate make useless call timedout function pushed on top of stack of tasks perform.
embedding checks @ top of raf loop good.
Comments
Post a Comment