Developer diary

Developer Diary #7: How Game Math Got Faster

We explain the number-math speedups, their measurement ranges, and the limits of changes in the final digits.

Contents
In a treasury hall, a young clerk points with a rod to an answer on a huge ready-made results table on the wall; behind him another clerk is buried under long scrolls of sums. On the table map in the middle, the provinces glow in changing colors.

In short: We sped up MKA Engine’s fixed-point number calculations. This number format helps different computers reach the same game result. Division on common values was 3.6 times faster in the measurement, and all five comparisons in an eight-worker scale-world run finished sooner. These results are not a speed guarantee for a complete game. The last digits of some exponent and power results also changed slightly.

Where did large-number calculations spend their time?

A grand strategy game repeatedly calculates many values each day, including population and markets. MKA Engine uses fixed-point numbers to keep a game consistent across different computers: the fractional part follows a fixed step, and calculations use that shared format. This consistency is useful, but some operations take longer with very large values.

In a scale world representing the late game, a profile—a sample of where processor time went—attributed 7.58 percent of its samples to the large-value division path in the baseline run. After the change, that share was 0.24 percent in the corresponding profile run. This is not the share of a game day; it is only the share seen in that profile’s processor samples.

Separate paths for common and large values

We used a shorter division path for common values while keeping the wider calculation path for very large values. For square roots, we start from a nearby prepared value and make one correction. For exponent and logarithm calculations—where a logarithm finds the exponent needed to reach a target value—we reduced repeated work; logarithms also reuse prepared reference values.

A value is matched to a nearby entry in a prepared table, then a small correction moves the result marker into place.

When an amount is split among several recipients, rounding can leave small remainders. We also made selecting those remainders require less sorting work; the measurement record’s test confirms that the distribution order and result stayed the same. This speeds up how the same game rule is applied, not the rule itself.

What do the operation checks and scale run show?

The measurements added to this diary later are reported as part of work that began on 16 October 2026. The source gives 16 October as the start of the work; it does not say the runs took place that day.

We compared individual number operations in a separate measurement using one million random values and the best of five runs for each operation. The machine was busy with other work, so ratios from the same run are more meaningful than absolute times by themselves. The operations did not all use the same input range; the square-root result in particular depends on the range.

OperationSpeed-up in this measurement
Division3.6 times for common values; 1.8 times across a broad range
Square root2.6–4.1 times, depending on the tested range
Exponent3.5 times
Logarithm3.6–4.1 times, depending on the tested range
Power3.5 times

These are small, separate tests on different input ranges, not one multiplier for all game math. For example, square root was 4.1 times faster up to 65,536 and 2.6 times faster in the range extending to one million.

We separately measured the effect on a whole simulation day in a scale world representing the late game. This run covered 300 days and used eight worker threads, or parallel work streams. All five before/after runs were shorter:

RunBefore (milliseconds/day)After (milliseconds/day)
12.211.74
22.151.60
32.881.93
42.762.16
52.852.12

Calculated from these five raw pairs, the reduction ranges from about 21 to 33 percent. The scale world’s final state summary stayed the same before and after; however, this single scenario cannot establish what would happen in another game that uses the changed exponent and power results.

Speeding up arithmetic without changing its rules

The goal was to do less work in the same number format rather than change the format and risk consistency. A square-root estimate is not the final answer by itself; the correction step completes it. In the tested inputs, the checked division, square-root and remainder-distribution results stayed the same. Exponent and power results changed in their final digits; comparison with high-precision reference values showed lower error.

The scope and limits of the measured gains

Because the final digits of exponent and power results changed, replaying an old save in a new version may produce a different result if it uses those operations. The scale world’s unchanged final state does not show that this risk is absent in other workloads. The measurement was also made in a particular scale world, not in a finished game.

The open question of a full-game measurement

The open question is whether a real grand strategy game, with its own mix of numbers, would see the same gain. This diary contains no full-game measurement, so we do not present the scale-world result as a broader performance guarantee.

Frequently asked questions

What are fixed-point numbers?

They keep the fractional part of a number in fixed-size steps. This helps different computers produce the same result for the same game calculation.

Did every operation get 3.5 times faster?

No. Results vary by operation and input range. For example, division across a broad range got 1.8 times faster, while the square-root tests ranged from 2.6 to 4.1 times. These are separate, small measurements.

Did the game result change?

The measured scale world ended with the same state summary, but that single result does not prove that every game using the changed exponent and power values will remain identical.

Did this measure a full day in a real game?

No. We measured a scale world representing the late game over 300 days with eight worker threads. A real game may have a different workload.

For fixed-point numbers and consistency, see Developer Diary #1; for the stages of a game day, see Developer Diary #4. For more on MKA Engine, visit the engine page and the developer diaries list.

Sources and related docs

You may also like

  • How is a strategy game's world map made?

    For MKA Engine we built a 27,357-location world map of 1337 from real data: how terrain, rivers, straits, population and location borders were made.

  • The road to a game engine

    How we started MKA Engine: reading four games, treating determinism as law, moving phase by phase with measurements, and where we are now.