Opened 10 years ago
Last modified 10 years ago
#2358 closed enhancement
[PATCH] Make entity selection faster — at Initial Version
Reported by: | Josh | Owned by: | Josh |
---|---|---|---|
Priority: | Must Have | Milestone: | Alpha 16 |
Component: | UI & Simulation | Keywords: | performance |
Cc: | Patch: |
Description
Right now, on every mouse movement event we call EntitySelection::PickEntitiesAtPoint. This sometimes happens multiple times per frame. The existing function loops through every entity that is selectable and computes their distance from the mouse which is very inefficient.
Here's a ~hour long profile of a normal game in 0AD: Image https://googledrive.com/host/0BwIjnJSd7iThRXRiN0ExcVVaeDQ/cpuprofile5.svg As you can see, entity selection is a good 1.5%. (I've seen over 3% in some profiles) The in-game profiler also confirmed the problem showing ~5-15 calls of the function per frame, each taking ~50ms.
The attached patch improves the situation by getting a smaller group of entities from the range manager's spatial subdivisions before checking the distance of each one. Initial measurements from the in-game profiler show the new function taking ~45us which is an improvement of over a hundred times.