Fix TPS calculation: clamp values above 20 instead of discarding them

The old code filtered out any instantaneous TPS sample > 20 with
`if (tps <= 20 && tps > 0)`. Because time-update packets arrive with
OS/network jitter, many measurements on a healthy server land slightly
above 20.0 and were silently discarded, leaving only sub-20 samples in
the rolling average. This caused the reported TPS to be virtually always
lower than the true server TPS.

A Minecraft server cannot genuinely run faster than 20 TPS (it sleeps
for the remainder of each 50 ms tick budget), so any measurement above
20 is definitionally timing noise. Clamp to Math.Min(tps, 20.0) instead
of discarding the sample so a healthy server's rolling average converges
to 20.0 as expected.

Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/826926c5-78fa-4059-ab8f-4abd209f120d

Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-04-03 16:24:38 +00:00 committed by GitHub
parent bca4532328
commit 744dcd73cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3912,11 +3912,15 @@ namespace MinecraftClient
{
DateTime currentTime = DateTime.Now;
long tickDiff = WorldAge - lastAge;
Double tps = tickDiff / (currentTime - lastTime).TotalSeconds;
double tps = tickDiff / (currentTime - lastTime).TotalSeconds;
lastAge = WorldAge;
lastTime = currentTime;
if (tps <= 20 && tps > 0)
if (tps > 0)
{
// A Minecraft server cannot genuinely exceed 20 TPS; values above 20 are
// caused by packet-timing jitter. Clamp instead of discarding so that a
// healthy server averages to 20 rather than being biased downward.
tps = Math.Min(tps, 20.0);
// calculate average tps
if (tpsSamples.Count >= maxSamples)
{