Skip to content

Trade ships spawn too fast when there are many ports and few trade ships #1703

@evanpelle

Description

@evanpelle

Trade ship performance analysis

I did a synthetic test where I let the game spawn up to 1,000 tradeships, with 100% probability each tick (not just every 10 ticks). Things are actually fine with a thousand ships if I have one or two ports, but if I have 20, and the rest of the world has 20... this instantly brings my powerful machine to its knees.

The cost isn't the 1,000 ships ... it's that they calculate their entire path when they spawn. For me about about 1.2ms per aStar.compute() call.

This seems to fit what I'm seeing. With trade ship generation uncapped, the simulation at max-speed goes sub real-time, and my 1sec performance timer seems to saturate at between 50-60 ships launched per second on the giant map. Here's my perf logging every 1 second of real-world time.

pathFinders: 69/92 active, A* invocations: 283, Total:  520.7 ms, ms/invocation:    1.84 ms
pathFinders: 68/89 active, A* invocations: 326, Total:  596.3 ms, ms/invocation:    1.83 ms
pathFinders: 71/87 active, A* invocations: 293, Total:  546.5 ms, ms/invocation:    1.87 ms
pathFinders: 77/93 active, A* invocations: 353, Total:  658.8 ms, ms/invocation:    1.87 ms
pathFinders: 76/92 active, A* invocations: 322, Total:  649.7 ms, ms/invocation:    2.02 ms
pathFinders: 76/96 active, A* invocations: 320, Total:  600.2 ms, ms/invocation:    1.88 ms

Late Game Lag

So, late game -- everyone embargoes each-other and all trade ships disappear. There are maybe 4 players left, and each person has like 80 ports. Because you're under 150 ships, there's a 1 in 5 chance a new ship spawns from a port every second. One person's embargos expire and ~320 ports start looking for places to send trade ships. For the next few seconds 60 trade ships get sent out each second

Image Image

Recommendation

I think this could be solved by just being more controlled with max number of boat spawns/captures each second. Limit everyone to 2-4 ship spawns/captures per second until the path finding can be optimized (run A* on nav mesh rather than the pixel grid?).

Note

This issue was originally posted by @Calrathan on Discord here

Metadata

Metadata

Assignees

Labels

GameplayFeatures that affect gameplayPerformancePerformance optimizationapprovedApproved for a PR, if you assigned to the issue.

Type

No fields configured for Bug.

Projects

Status
Triage

Relationships

None yet

Development

No branches or pull requests

Issue actions