NOPerf · What we learned

How finding nearby units works

The server often needs a list of nearby units. Spatial builds the same list with less bookkeeping.

The map is split into areas. To find nearby units, the server checks the areas around a spot and lists the units inside them.

Made-up example map. These steps count actions in the example, not a measured speedup.

Finished. Before needed 8 steps; After needed 4. Both lists are the same: Plane 1, Truck, Plane 2, Ship.

Before

First list the areas; then collect their units.

Areas to check

  • Area 1
  • Area 2
  • Area 3
  • Area 4

Nearby units

  1. Plane 1
  2. Truck
  3. Plane 2
  4. Ship

Done after 8 steps.

After (Spatial)

Collect the units while visiting each area.

Areas to check

  • Not needed

Nearby units

  1. Plane 1
  2. Truck
  3. Plane 2
  4. Ship

Done after 4 steps.

Same result: Plane 1, Truck, Plane 2, Ship, in the same order.

Spatial skips the extra list, not any units. That makes this one task cheaper; it has not been shown to make the whole server faster. See the results.

All 8 steps as text
  1. Before writes down Area 1. After visits Area 1 and adds Plane 1.
  2. Before writes down Area 2. After visits Area 2 and adds Truck.
  3. Before writes down Area 3. After visits Area 3 and adds Plane 2.
  4. Before writes down Area 4. After visits Area 4 and adds Ship. After is finished.
  5. Before goes back to Area 1 and adds Plane 1.
  6. Before goes back to Area 2 and adds Truck.
  7. Before goes back to Area 3 and adds Plane 2.
  8. Before goes back to Area 4 and adds Ship. Both lists now match.
Technical details

In the real game, areas are grid cells, visited column by column, and each cell’s units are read from last to first. Duplicates and empty (null) entries are kept. The query details page walks through a fuller example with those cases. The other plugins are described in the developer guide.