deepstreamIO / deepstream.io-client-js

The Browser / Node.js Client for deepstream.io
Other
294 stars 109 forks source link

onHeartbeat performance issue #235

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hi,

The Socket.prototype.onHeartbeat calls clearTimeout and setTimeout. These two calls are very heavy and could be replaced with one static timer with a fixed interval that simply checks a boolean "gotPing" like this:

static, fix timer: if (gotPing) { gotPing = false; } else { // fail the connection }

onHeartbeat: gotPing = true; // setting a boolean is far faster than clearing/setting a timer

This performance problem is very easy to spot in the space shooter demo app where the FPS drop dramatically on any kind of message receives due to these calls.

WolframHempel commented 7 years ago

Thanks, great find. Absolutely agree - should go hand in hand with #237 (moving out of engine.io)

ghost commented 7 years ago

Maybe it is as simple as removing this.emit('heartbeat'); from Socket.prototype.onPacket?

ghost commented 7 years ago

Wait what? So this is engine.io code I'm looking at?

WolframHempel commented 7 years ago

Yup, afraid so. There's quite a few of these, hence #237