Need help fixing my game - Battlefield 2

Hello friends : )

I have an issue with Battlefield 2 for many years now. The game runs smooth ans snappy at the beginning, but after a few minutes I start getting huge desync. The lag is not “fps lag” or “mouse lag”. it seems to be solely connected to my model not reacting to my input and my mouse occasionally skipping, especially at medium speed.
When I strafe, my model will get pushed a little bit more after I stop. Strafe shooting will miss because of parallax error. Movements feel extremely heavy and unresponsive. Sometimes I press the jump key and it will take nearly half a second until the model jumps. This will be worse if I give a lot of input. If I stand still it gets better.
Now the weird part: If I alt+tab or if I lock the fps to 1 for a few seconds and relock it to a playable value, it will get better. When I tab back into the game or unlock fps, player models will jitter (interpolation reset, I guess). Then the game is smooth. I can do it a couple of times but the effect wears off. After a while it doesn’t work anymore and I have to restart the game. Sometimes I alt tab enough and the game becomes smooth and stays like that. The problem will sometimes completely be gone in the middle of the night. I suppose this is either because there is less strain on the internet or we are dealing with an electrical problem or it is the game.
Getting into Windows tweaking has mitigated my problem, but I still get it. The problem exists both on Windows 7, Windows 8.1 and Windows 10. I have tried many, many, many things. First got into tweaking net settings. This was my trip into the rabbit hole and I tried a lot of fixes. Nothing got rid of the problem. I talked to people that mod the game and they said it has to do with interpolation, however, not everyone in my community has it. People with stable internet and minimal jitter (NL, NOR, SWE) claim to not experience it. It will also be much worse for me on certain servers (Not connected to ping, which is max 25). I have asked many people and nobody could really help.

I have also moved places a couple of times and the problem persisted. Others I talked to, say they changed ISP multiple times without effect.

My system:
4790k
16 GB DDR3-2400 CL 10
GTX 970
144 hz monitor

Would be really grateful if you had any ideas

It this point I feel pretty lost, tbh.
Maybe someone here can give me a small hint, anything. A way to pinpoint the problem. A tool to analyze what causes it, so I can at least work with some metric that isn’t my own perception.

Thank you so much, Manekk

This sounds like a problem with the game’s internal clock. Most of these multiplayer games like to sub-divide the game simulation into constant time frames and some parts of their logic can skip frames if things are running behind and others must step through each frame to produce accurate simulation results even if it is running late.

It sounds like you are running tremendously late to the point where the game’s only hope of working correctly is a clock resync that is happening when you alt-tab.

I do not do much work on multi-player games unfortunately (though ironically I used to work for a company known for MMORPGs), so I do not know what sorts of data / input events could be creating a backlog of unprocessed frames. I think it’s unlikely that an FPS like Battlefield would be using a network protocol (e.g. TCP) that requires delivering and processing packets in-order so packet loss is probably not to blame.

There’s something known as “buffer bloat” that could still affect the game even if it uses UDP; this is a problem where your router does not prioritize low-latency / high volume network connections over some other device on your network gobbling up lots of bandwidth (e.g. Netflix). If that is your problem, your router might be delivering you tons of really old packets in large bursts and this would probably cause chaos while the engine figures out what to do with all the info. Might be worth checking for QoS settings in your router.

Thank you so much for your response, Kaldaien!

Your theory makes a lot of sense. This would mean that one of the game’s APIs is not working as intended and is losing sync, I suppose? I have meddled with Windows Timers and have tried several variants of hardware timers and synthetic timers, HPET, RTC, TSC, etc. All with no success. The problem must lie in the game itself, then, I suppose. Any way to diagnose this? Find the buffer that fills up?
Considering your theory about bufferbloat. I have benchmarked my network quite extensively. Tried QoS and set the game to the highest priority. When I game, the only device running is my PC and my phone. My PC has any kind of windows update disabled and I am very tedious with unnecessary programs or services running in the background. I even tried putting my phone to airplane mode, because I have dug so far, that I am starting to encounter tin foil hat solutions to my problem. People are naming EMI or “dirty power” as causes.
I even modded my bios, eliminating spread spectrum and any kind of power down, latency tolerance, C-States, P-States and power saving mechanisms, you name it.
My PC runs absolutely great now, just not my game.
Another person suggested that ISPs coalesce packets without my consent and that I am more or less playing round-robin with my neighbours. The game uses UDP, like most shooters.
I also disassembled the game’s EXE and some DLLs to maybe find a clue, without luck. Possibly because I don’t know the two languages that were used: Python and C.
Do you think it might be beneficial to use a program like process hacker to change thread priorities? Anticheat is not an issue. I have the game running with a slightly lower priority to give some breathing room to the services.
My game is a bit like an athlete at the paralympics. Highly optimized, but also handicapped.

So I would like to give an update on my own thread in case anyone is working on the same issue, since I have found out more about the problem since I made this post.

The issue stems from a problematic implementation of server-side interpolation with a closed loop reaction at key sync frames.

This can be mitigated by changing the size and frequency of the network packets, although the only way to do this is assembly hacking. Another issue that causes the desync is the unpredictable and unstable system scheduler used by windows. I am currently experimenting with different time sources to improve scheduling reliability. The best experience I had so far was by using PMT as clock source. The only way the game gets clock is through QueryPerformanceFrequency and QueryPerformanceCounter.
I also noticed that running the game server on linux yields improvements, especially compared to the newest windows server builds.
I might update this in the future to leave bread crumbs for anyone trying to google this.