perf: Remove allocation overhead when retrieving labels for Waypoints() and PolygonTriggers()#2761
Conversation
…() and PolygonTriggers()
|
| Filename | Overview |
|---|---|
| Generals/Code/GameEngine/Include/GameLogic/TerrainLogic.h | Changes getPathLabel1/2/3 return type from AsciiString (by value) to const AsciiString& to eliminate per-call heap allocations; all call sites safely copy or compare the result without storing the reference. |
| Generals/Code/GameEngine/Include/GameLogic/PolygonTrigger.h | Changes getTriggerName return type from AsciiString (by value) to const AsciiString& to eliminate per-call heap allocation; existing callers all assign to AsciiString by value or consume the result inline. |
| GeneralsMD/Code/GameEngine/Include/GameLogic/TerrainLogic.h | Zero Hour mirror of the Generals TerrainLogic.h change; identical update to getPathLabel1/2/3 return types. Same safety assessment applies. |
| GeneralsMD/Code/GameEngine/Include/GameLogic/PolygonTrigger.h | Zero Hour mirror of the Generals PolygonTrigger.h change; identical update to getTriggerName return type. Same safety assessment applies. |
Sequence Diagram
sequenceDiagram
participant AI as AI Unit (per frame)
participant SC as ScriptConditions / isPurposeOfPath
participant WP as Waypoint
participant PT as PolygonTrigger
AI->>SC: check waypoint path label
SC->>WP: getPathLabel1() [before: AsciiString copy]
WP-->>SC: "const AsciiString& (no alloc)"
SC->>WP: getPathLabel2()
WP-->>SC: "const AsciiString& (no alloc)"
SC->>WP: getPathLabel3()
WP-->>SC: "const AsciiString& (no alloc)"
AI->>SC: check polygon trigger area
SC->>PT: getTriggerName() [before: AsciiString copy]
PT-->>SC: "const AsciiString& (no alloc)"
Reviews (1): Last reviewed commit: "perf: Remove allocation overhead when re..." | Re-trigger Greptile
This PR reduces the allocation overhead seen when waypoint path labels and polygontrigger names are retrieved.
In mod maps with a lot of path scripted ai, such as Cobal Rush, waypoint labels are retrieved and compared every frame.
This will occur for every AI unit that is pathing along the waypoint. Polygon triggers also have a similar issue where they can be repeatedly compared every frame per scripted unit.
The following shows the side effects of this change for waypoint path labels.
Before:

After:

In game the most significant observation was that the first wave in Cobalt Rush went from stuttering to smooth.
The average FPS also significantly increased when observing the first wave and the camera also stopped stuttering.
The above flame graphs were captured in a debug build, but the stuttering still occurs in a release build and is alleviated with the same fix.