# Spatial Hashing

## **Spatial Hashing Interest Management**

{% hint style="warning" %}
For better performance try [Hex Spatial Hashing](https://mirror-networking.gitbook.io/docs/manual/interest-management/hex-spatial-hashing) instead.
{% endhint %}

First things first: **"Spatial Hashing"** sounds complicated so that we network programmers can stroke our egos. The technique is actually pretty simple, and if you used uMMORPG before then you probably remember this as **"Grid Checker"**. We go with "Spatial Hashing" anyway since that's the industry term.

### Setting Up

Add the **Spatial Hashing Interest Management** component to the same object as your **Network Manager**:

![](https://462154250-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MGmQrf2z6FL0ZpExPAn%2Fuploads%2FUQnA2MICbOCGUZheWPGE%2Fimage.png?alt=media\&token=1a66b5f7-5490-4824-88f5-6463317d1ed9)

### **How It Works**

Previously we **Vector3.Distance** checked each spawned entity against each connection. Instead, we put each spawned entity into a **Grid** and for each connection, we send all **8-neighbor** grid entries to it.  This is extremely fast. In early uMMORPG tests, it was 30x faster than distance checking. The algorithm is less complex, so it scales well to large amounts of entities.

![Source: https://www.dynetisgames.com/2017/04/05/interest-management-mog/](https://462154250-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MGmQrf2z6FL0ZpExPAn%2F-MWIEnySUkrRxUVX0X8d%2F-MWIFAsg-sK23fw3O_Cw%2Fimage.png?alt=media\&token=277d227a-60b9-4092-8970-abbe6cc89d96)

{% hint style="info" %}
Check out Mirror's **Benchmark** example. It uses Spatial Hashing and displays a runtime slider to let you play around with the visibility range.
{% endhint %}
