Opened 9 years ago

Closed 8 years ago

#615 closed defect (no change required)

fancy_selected_units eats too much fps + doesn't draw anything

Reported by: Bluestone Owned by: Floris
Priority: minor Milestone:
Component: BAR Version:
Keywords: Cc:

Description (last modified by Bluestone)

give all, select all, zoom out -> for me it then uses 2-3x the cpu time of the entire chili framework, which is far too expensive for what it does

in 96.0+, doesn't draw anything

Change History (13)

comment:1 by Bluestone, 9 years ago

Description: modified (diff)

comment:2 by Bluestone, 9 years ago

Description: modified (diff)

comment:3 by Floris, 9 years ago

Yes I am aware of this. I just added it so you've something to experience already.

I gave it to jK a while ago, because he said he would optimize it. But then.... he had a lua error and never got it working. I don't know why.

So I was also curious if you guys could get it to start up. Obviously bluestone did succesfully.

comment:4 by Bluestone, 9 years ago

Component: BA trunkBAR

comment:5 by Bluestone, 9 years ago

Yep, it displayed fine for me, but I didn't test it ingame.

comment:6 by Bluestone, 9 years ago

after [2346], [2350], [2354] it has a sane way of tracking which units are selected and doesn't make crazy tables everywhere. as a result the performance is improved by about 60% but is still awful.

still needs something added to avoid drawing for units that are currently offscreen, but this won't be a huge gain.

i haven't even looked at all the gl calls - essentially all of its time spent is now on gl calls and there are simply too many of them.

further things to do: (1) don't draw for off-screen units (2) don't draw (detail) when zoomed far out (3) reduce amount of stuff re-drawn per unit

Last edited 9 years ago by Bluestone (previous) (diff)

comment:7 by Bluestone, 9 years ago

Owner: set to Floris

comment:10 by Bluestone, 9 years ago

Description: modified (diff)

comment:11 by Bluestone, 8 years ago

Type: defectperformance

comment:12 by Bluestone, 8 years ago

I read the code and a one cause of the perf issues is that you are iterating over the hashtable of all currently selected units 15 (!!!) times on each drawframe.

The reason is that you call DrawSelectionSpottersPart (and/or DrawSelectionSpotters, which is a proxy for calling DrawSelectionSpottersPart 6 times in a row!) again each time you want to draw something. Then inside DrawSelectionSpottersPart, inside each pairs() loop, each unit individually checks which of the items it has been called to draw.

The cost of iterating through hashtables with pairs() is high and when possible lua coders strongly avoid doing pairs() operations that take place frequently (note that ipairs(), which iterates over arraytables, is faster but still fairly expensive). Basic info on performance issues of lua tables can be found here ​​

You should make a table of which items you want drawn, then iterate over unitIDs in selectedUnits[teamID] precisely once per team per drawframe, and draw them all within that single loop.

You should also investigate the suggestions above (one is already done in [2972]).

comment:13 by Bluestone, 8 years ago

Floris: any progress on this?

comment:14 by Bluestone, 8 years ago

Description: modified (diff)
Priority: majorminor
Summary: fancy_selected_units eats too much fpsfancy_selected_units eats too much fps + doesn't draw anything
Type: performancedefect

[3209] moved to etc - too many issues still + much untidy code

comment:15 by Bluestone, 8 years ago

Resolution: no change required
Status: newclosed
Note: See TracTickets for help on using tickets.