Opened 10 years ago
Last modified 10 years ago
#2358 closed enhancement
[PATCH] Make entity selection faster — at Version 1
Reported by: | Josh | Owned by: | Josh |
---|---|---|---|
Priority: | Must Have | Milestone: | Alpha 16 |
Component: | UI & Simulation | Keywords: | performance |
Cc: | Patch: |
Description (last modified by )
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: 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.
Change History (2)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
by , 10 years ago
Attachment: | fast-select.diff added |
---|
Second version, ignore all the whitespace stripping. (vim did that automatically) See helpers/Selection.cpp for the main changes. This version adds the ability to specify the selection range from JS.