Blog

Chasing milliseconds: what a slower PC taught us about performance

MJOLNIR Coremultiplayerperformance

Most of MJOLNIR's development happens on a fast PC: a Ryzen 9 7950X3D with an RTX 5090. Any game runs well on it, which is exactly the problem: it hides slow code. So this week we did the opposite and ran a full performance pass on our slowest test PC.

Development PCTest PC
CPURyzen 9 7950X3DRyzen 9 7900X
GPURTX 5090GTX 1080 Ti
Settings4KMedium, 1080p, VSync on
Windows Defender real-time scanoffon

That last row turned out to matter most.

The culprit: files read right after they change

MJOLNIR is several mods (the HUD, the lobby, the level loader) plus small native libraries, all running inside the game. They talk to each other a lot: the HUD asks for the state of the Pelican Warfare zones, the lobby passes your match to Discord, joining a match hands a map name from one part to another. For a long time much of that talk went through small text files: one side writes a file, the other reads it.

On the development PC a file read costs about 0.2 ms, so nobody noticed. On a PC with Windows Defender's real-time scan, which Windows turns on by default, opening a file a moment after it was rewritten waits for Defender to scan it. That's about 5 ms each time. An unchanged file still opens in 0.1 ms. It's only the read-after-write that costs, and that's exactly what a handoff through a file is.

5 ms sounds small. But the game draws a frame every 16 to 22 ms, and some of these handoffs happened eight or nine times a second.

How we measured

  • The hitch log. The HUD already ships one: it notes every slow frame, where you were standing, and which of our scripts ran during it. At the end of each match it prints a summary: frame times, hitches, and how many milliseconds per second each of our script loops took.
  • A file and call profiler, for development only. It counted and timed every file our scripts opened and every call into our native code. That's what found the 5 ms reads.
  • A frame recorder, which splits each frame into game, render and GPU time without slowing the game down. That's how we could tell our own hitches from the engine's.

For this post we ran the same scenario twice on the test PC, once with the mods as they were before this pass and once after. The development PC hosted Pelican Warfare, and the test PC joined a match already under way, played to the end, then stayed for the next full match. Same PCs, same map, same settings. Only the mods changed.

The results

Time our scripts held the game thread, per second of play (lower is better):

Script loopBeforeAfter
HUD21–49 ms2.6–4.5 ms
Lobby Discord presence7.5 ms0.1 ms
Everything else together1–2 ms0.6–1.6 ms
Total31–57 ms3.2–6.2 ms

Frame times on the test PC (lower is better; the median is the typical frame, p95 and p99 the slowest 5% and 1%):

Before: join under wayBefore: full matchAfter: join under wayAfter: full match
Length4 min 19 s6 min 49 s6 min 10 s6 min 49 s
Median frame22 ms20 ms22 ms21 ms
p95 frame28 ms31 ms25 ms25 ms
p99 frame31 ms32 ms26 ms26 ms
Hitches during play31533
Worst frame during play87 ms70 ms84 ms38 ms

The median is 20–22 ms in all four runs: on this PC the graphics card sets the typical frame. The difference is in the slow frames. Before, p95 and p99 sat 6 to 12 ms above the median, and that gap is the file reads landing on top of a normal frame. After, the slowest 1% of frames sit 4 to 5 ms above the median. In the full match, the 15 hitches during play dropped to 3, all of them 31–38 ms frames at the Pelican launch. In both joined matches the worst one is the same: the team armour colours being applied as you join. That one is fixed too, after these runs (below). Most of the slow frames a match still has, about 16, come in its last second, at the round end.

What we changed

The hot paths (two handoffs that ran every second):

BeforeAfter
HUD reading the Warfare zone state, 8–9 times a second50 ms per secondread from memory, ~0
Discord presence handed between the HUD and the lobby5.5 ms per secondin memory, ~0

The hitches:

BeforeAfter
Post-game vote screen: a check for hidden menus60–72 ms frame every 1.5 sgone
A kill-feed line after a player's avatar was unloaded26 msunder 8 ms
The Pelican launch: three zone walls built at onceone 48–52 ms frame31 and 36 ms frames
Team armour colours at a match startone 104–107 ms frame23 ms at most
Team armour colours when you join a matchone 55–63 ms frame8 ms at most

Nearly every other handoff between our mods and native code now goes through memory: joining, the lobby, the hub, map installs, kill floors, Halo 2's lifts and bots. Costs per use on the test PC:

HandoffBeforeAfter
Each call to mjolnircore.com (heartbeats, player names, match results)~11–14 ms~0
Each retry of a joiner's sound setup~13 ms~0
Placing the map when you join~11 ms~0
The lobby's connection details5 ms~0
Pelican Warfare's state file for test tools0.8 ms per secondnot written on players' PCs

Text files are still used where they belong: logs, saved settings, and anything another program reads, such as the launcher.

What's still there

Being honest about what we didn't fix:

  • The end of every match. There's about a second of slow frames (70–90 ms), then one long one (~285 ms) as the round ends and the world unloads. Our scripts are idle then, on both PCs; it's the game's own round end.
  • Lua garbage collection. Our scripts' memory cleanup takes a 20–25 ms frame about three times a match.
  • Joining. Two one-off costs of about 100 ms each remain while the join's loading screen is up: reading the map's level file once, and the game starting your side of the match. We cut the rest: re-reading the level file (92 ms to 1 ms) and the HUD's first tick (60–66 ms to 39–43 ms).

Why it matters

The PCs we build on aren't the PCs most of you play on. Every few milliseconds we spend on the game thread comes out of your frame time, and the cost is highest on the PCs that have the least to spare. From now on we profile on the slow PC first.

These changes shipped in mods 0.57.0, alongside Pelican Warfare's reinforcement waves, the Covenant and voice lines. If you still see stutter in a match, the HUD's hitch log (MJOLNIRHud\hitches.log) records where and when, and it's the most useful thing you can send us.