Opened 8 years ago

Last modified 5 years ago

#3925 new defect

[PATCH] Stop-gap optimizations in the Vertex Pathfinder

Reported by: fsincos Owned by:
Priority: Should Have Milestone: Backlog
Component: Simulation Keywords: pathfinding
Cc: Patch:

Description

This ticket contains stop-gap measures to improve the performance of the Vertex Pathfinder before the impending rewrite (see #1942) since that will take some time to be done and tested. This can also be considered as a sub-ticket of #3588.

Currently implemented improvements:

  • Clip out vertexes that are in obstructions and thus always not visible. This removes quite a lot of visibility checks in some situations (e.g. huge combat demo). The check itself is rather cheap.
  • Only partially sort the edgeSquares since a full sort would be wasteful. This improves the performance in crowded scenarios by ~5%; in my testing it also miraculously improved the performance of ComputeShortPath as well (which might be due to the distance heuristic for "probability to block rays" being worse than "just use the previous order" for squares that are further away). There is some opportunity for tuning in the form of branching / length of the partial sort since I just used some reasonable threshold.

Further improvements:

  • Memory: Many vectors of edges and vertexes get thrown around in the code, it could be worthwhile to reduce this memory churn.
  • Handle the case where the goal is unreachable in a sane way instead of exhausting the search space (in search of wormholes?).
  • Currently, the search space is a square around the start point. This could be changed to a more reasonable search space, reducing the bugs from too small search spaces (like units running circles around a blob of other units as they only "see" the ones on their side) and improving performance (less "wasted" vertexes and edges).
  • "Lazy A*": Because of the ever-changing nature of the environment, it is not a good idea to follow long paths that only improve the distance to the goal slightly. This could be stopped by selecting the path end point as the point with minimal h + g*(some constant) instead of h.

Attachments (4)

Clip.patch (2.3 KB ) - added by fsincos 8 years ago.
First patch of the series, containing Clip and Partial Sort.
TerrainEdges.patch (6.8 KB ) - added by fsincos 8 years ago.
AddTerrainEdges rewritten to not use the "segments" vectors.
Squares.patch (13.2 KB ) - added by fsincos 8 years ago.
Unit shapes are squares; use that to optimize the TestRayAASquare-based approach even further. (+style adjustments)
Squares.2.patch (7.1 KB ) - added by fsincos 8 years ago.
Unit shapes are squares; use that to optimize the TestRayAASquare-based approach even further.

Download all attachments as: .zip

Change History (13)

comment:1 by Itms, 8 years ago

Really nice, you only forgot to improve the conditionals with some newlines.

Instead of

if (longconditionnumberone && longconditionnumbertwo && longconditionnumberthree && longconditionnumberfour)

write

if (longconditionnumberone &&
    longconditionnumbertwo &&
    longconditionnumberthree && 
    longconditionnumberfour)

using tabs to indent and extra spaces if necessary.

comment:2 by Itms, 8 years ago

Sorry I think my explanation was misleading: I meant

[tab][tab]if (foo &&
[tab][tab]    foo2)

(I was talking about the higher-level indentation)

by fsincos, 8 years ago

Attachment: Clip.patch added

First patch of the series, containing Clip and Partial Sort.

comment:3 by Itms, 8 years ago

In 18090:

Slight improvement to the short range pathfinder. Patch by fsincos, refs #3925

comment:4 by Itms, 8 years ago

Keywords: review removed

comment:5 by elexis, 8 years ago

Don't forget to add yourself to programming.json with the next patch.

by fsincos, 8 years ago

Attachment: TerrainEdges.patch added

AddTerrainEdges rewritten to not use the "segments" vectors.

comment:6 by Stan, 8 years ago

Any input on the performance improvements of these patches ?

by fsincos, 8 years ago

Attachment: Squares.patch added

Unit shapes are squares; use that to optimize the TestRayAASquare-based approach even further. (+style adjustments)

by fsincos, 8 years ago

Attachment: Squares.2.patch added

Unit shapes are squares; use that to optimize the TestRayAASquare-based approach even further.

comment:7 by fsincos, 8 years ago

The first patch mainly makes AddTerrainEdges look nicer. The "Squares" patch is not fully fleshed out: Some replays diverged from the original, the performance was overall unchanged or improved quite a bit (up to 15%) for the other replays. In longer games the reduced memory fragmentation seals the deal.

As the Square patch isn't ready yet, no review tag for now.

comment:8 by sanderd17, 8 years ago

Looking at the TerrainEdges patch. Why did you take some type definitions outside the loops (like a, b, Edge1 and Edge2)? I don't think this would cause any performance gain (the compiler is smart enough), while it also doesn't reflect the scope of the variables anymore (they're only used in the loop).

Version 0, edited 8 years ago by sanderd17 (next)

comment:9 by Imarok, 5 years ago

Component: UI & SimulationSimulation

Move tickets to Simulation as UI & Simulation got some sub components.

Note: See TracTickets for help on using tickets.