beyond-all-reason / Beyond-All-Reason

Main game repository for Beyond All Reason.
https://www.beyondallreason.info/
Other
1.79k stars 299 forks source link

High CPU usage for metal spots widget #825

Open 6AKU66 opened 2 years ago

6AKU66 commented 2 years ago

Metal spots widget consume a lot of CPU when option metalspots show values enabled. изображение_2022-02-22_111609

Values off No values

Values on With values

Beherith commented 2 years ago

Turns out that font:begin() + font:print() is not only not reentrant, but extremely expensive.

MasterBel2 commented 2 years ago

Text rendering performance is sort of an engine-side concern. Can we close this issue as irrelevant? Better than having it lay around adding to the clutter.

sprunk commented 2 years ago

Engine's font rendering and the way Lua orders the engine to render fonts are somewhat orthogonal. Measure whether the engine calls themselves or all the Lua overhead around them is what's taking so long.

MasterBel2 commented 2 years ago

I've been assuming that because drawlists are compiled and stored GL driver / graphics card side (idk where just not even in the engine) it's pretty clear this performance hit is to do with just how long it takes to draw text.

Is that not a safe assumption? If not I'll definitely look into it because I'd love text rendering to be cheaper

sprunk commented 2 years ago

Is that not a safe assumption?

Has anybody ever measured it?

MasterBel2 commented 2 years ago

a) I thought it was implied in the word assumption that no, I haven't tried b) the assumption basically outlines "the drawing doesn't even happen in lua, so there's nothing even there to measure"

As far as I understand the callList code, it hands an integer to the engine which hands an integer to GL. That's it. There's no additional overhead engineside / luaside that exists to measure to have text in a draw list rather than anything else you might put in a draw list – except the GL instructions that were compiled into the draw list in the first place. That said, I have a habit of not seeing very obvious things (to the point of my & others frustration) so if I've missed something or misunderstood how drawlists work I'd love to know.

I've also previously established through profiling that drawing text not in a drawlist takes much longer than drawing text that is in a drawlist.

MasterBel2 commented 2 years ago

On another note, might RTT be useful here? I sorta forgot that existed for being in the BA / Spring 103 world for so long

saurtron commented 1 week ago

This one looks like it's already fixed. I checked and metalspots doesn't seem to consume much processing or memory, about 0.2-0.3% at game start, and very small memory with some spikes of 15kB, nothing worrying imo. @Beherith did a recode when introducing the AtlasOnDemand so I guess that did it. Please correct me if I'm wrong.

It does seem to spike a bit specially on mem load during the first frames but then it goes down. I opened a PR to address this: https://github.com/beyond-all-reason/Beyond-All-Reason/pull/3903

There are also checks every 151 frames that cause small spikes, not sure if those are needed but not so worrying as to have an issue open imo. Would be nice to know why those checks exist though, the widget is supposed to show the right ones by listening to events. Maybe it's to remove the rings when an enemy mex is seen?

What I noticed is the settings option to show texts doesn't do anything any more (showValue var at gui_metalspots.lua), maybe it's time to remove it?. The opacity option also doesn't seem to do anything any more (opacity var), well actually the opacity option doesn't seem to be in settings gui just in code and not really used there.

If you want I can also remove the settings options, at least the not working one should be commented out from settings gui to avoid confusing ppl. I was actually wondering all the time, since it says it's expensive, and tried toggling it some times and didn't seem to do anything. Turns out it doesn't XD.