Back to the blog

Server cost per player: how an eight-player battle fits on a single CPU core

October 31, 2026 7 min read

For an RTS that runs a server-side simulation, the cost per player is set by CPU time, not by traffic. If one step of a match does not fit into the 50 ms budget, each match needs more cores, and the price of every active player rises with it. This study shows how we brought that time down on Morvek’s hardest map.

The problem

Morvek’s simulation takes 20 steps a second, and a match runs on a single thread. That is a deliberate choice: behaviour stays deterministic, and one match crashing does not take the others with it. It also creates a hard limit: a step must finish in under 50 ms in every circumstance.

The worst case was the “giant” map: 576×576 tiles, eight players, 1,200 units and heavy AI opponents. The first measurements showed:

  • the median full step, network included, was 28.4 ms, more than half the budget;
  • in a large town with many buildings, the AI routine that looks for idle villagers pushed the 99th percentile step time to 274 ms, more than five times the budget;
  • encoding the views, so every player receives their own fog-filtered delta, took 14.6 ms by itself.

The solution

1. Native Rust kernels, identical to the byte

We also wrote the hottest calculations (A* pathfinding, tile distance fields, line of sight, region distances) in Rust, and load them into the Node.js worker through N-API. The condition was strict: the native kernel has to return the same bytes as the TypeScript reference, otherwise the server and client simulations would diverge. Parity tests check this. If the native module does not load, the system keeps running on the TypeScript path.

2. Shared public state when encoding views

Previously we built every player’s view from scratch. Now each unit’s public state is kept once, with a version, deltas are built in place in preallocated buffers, and the deltas use a fast FNV-1a checksum instead of SHA-256. (Full snapshots still use SHA-256.)

3. We no longer copy the world on every step

For fault tolerance, the server used to clone the entire game state twenty times a second, giant map included. Today the step’s result stays in memory and is only published once the durable save has succeeded. On failure we do not roll back. We retry.

4. A pathfinding budget, used as a valve

Pathfinding gets a fixed node budget per step. When it runs out, the remaining units get a path on the next step. That also bounds the worst case: the 99th percentile of movement calculation dropped from 8.6 ms to 7.0 ms, and we hit the budget in only 1.9% of steps.

5. A smarter AI, not brute force

The breakthrough in searching for idle villagers was not a native rewrite. It was a grid-based bucket index and memoization. We measured it on the same synthetic town: 401 buildings and 966 units.

6. Garbage collection and scheduling

Growing V8’s young-generation heap cut the longest garbage-collection pause from 3.2 ms to 2.1 ms. The scheduler uses absolute deadlines instead of setInterval, so steps do not drift relative to each other. Capacity is handed out with points weighted by map size: a giant map takes four times the room of a small one.

Measured results

−60%

View encoding (median)

14.6 ms → 5.9 ms, eight players, a real WebSocket room

−47%

Simulation (median)

6.0 ms → 3.2 ms, with native kernels, 1,600 units

−86%

99th percentile step time, large town

274 ms → 39 ms after indexing the AI

21 ms

99th percentile step time, giant map

8 players, 1,200 units, 7 heavy AIs, 42% of the 50 ms budget

  • The median full step, network included, fell from 28.4 ms to 20.5 ms.
  • The slowest run of the idle-villager search fell from 327 ms to 26 ms.
  • Continuous integration runs the giant-map benchmark on every change and fails the build above a 40 ms 99th percentile. Performance cannot quietly regress.

The point: even the hardest match stays well inside the budget on a single thread. The same server can therefore host more matches in parallel, and that directly lowers the server cost per active player. None of this comes from giving up the experience, meaning a lower tick rate or fewer units.

Have a game idea?

We would like to help you build it.

Describe it in a few sentences and we will get back to you. Your idea stays confidential.

Get in touch
with us

This site uses cookies to improve your user experience. By using this site, you accept our use of cookies.