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.
Play is off because your device asks for reduced motion. Use Next to go one step at a time.
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
- Plane 1
- Truck
- Plane 2
- Ship
Done after 8 steps.
After (Spatial)
Collect the units while visiting each area.
Areas to check
- Not needed
Nearby units
- Plane 1
- Truck
- Plane 2
- 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
- Before writes down Area 1. After visits Area 1 and adds Plane 1.
- Before writes down Area 2. After visits Area 2 and adds Truck.
- Before writes down Area 3. After visits Area 3 and adds Plane 2.
- Before writes down Area 4. After visits Area 4 and adds Ship. After is finished.
- Before goes back to Area 1 and adds Plane 1.
- Before goes back to Area 2 and adds Truck.
- Before goes back to Area 3 and adds Plane 2.
- 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.