fishfolk / jumpy

Tactical 2D shooter in fishy pixels style. Made with Rust-lang 🦀 and Bevy 🪶
https://fishfolk.org/games/jumpy/
Other
1.59k stars 116 forks source link

Performance degrades in Network play after multiple map transitions #984

Closed MaxCWhitehead closed 2 months ago

MaxCWhitehead commented 2 months ago

Description

Haven't dug into this much but in network play performance gets worse (things feel laggy) after several map transitions.

Quick run with sampling profiler shows a lot of time on other threads with sockets.

Wondering if spawning extra async tasks / mis-managing existing sockets when transitioning map. Thinking maybe other threads are polling buffer or something and contending with locks - just spitballing. We shouldn't block on polling socket, but maybe the write is blocking? Doesn't quite make sense but something sus is going on.

The very limited profiler instrumentation of game loop doesn't catch this, but I'm going to find my stashed changes adding puffin scopes to capture more of bones core loop + network session runner and commit those and step through things a bit if that does not illuminate things.

Tracy profiling with spans lets us capture async tasks which would be helpful - but I won't worry about that for now, but I am always looking for more excuses to add that back in as I liked it a lot in the past pre-refactor heh.

MaxCWhitehead commented 2 months ago
image

Towards the left we have a step bones scope that took 6.5ms. About ~10ms later, we step bones again but very little work is done (~700us). ~20ms later again with little work done. It's scheduled a few times, but does not run again and actually do work / take 6.5ms and execute game session until 70ms from last good update.

Seems time is not managed right on net session runner. There are some frame skips and freezing, but it is sporadic and does not appear to be happening constantly or to be what is blocking advancement.

It seems like time accumulated does not match wall clock time based on what is happening in puffin and tracy, puffin frame time accumulation looks right, but given tracy wall clock time of scheduling bones steps, would expect multiple net session steps, but only see one in puffin each time network steps.

It's possible it could be freezing dropping time, but doesn't look like it immediately. Will probably add a tracy marker on freeze / skips and see if can verify we are not consuming time for those reasons + find out if the passed in timestamp could be wrong. It would make sense if there was some sort of net transit issue causing this though considering that is mostly what changed here.

MaxCWhitehead commented 2 months ago

Oh it's a funny bug - when restarting net session runner and passing in network fps, I was passing in the current net fps instead of original game fps, so the NETWORK_FRAME_RATE_FACTOR was continuously applied lowering framerate heh.