Jump to content

Path Lag Partial Fix


Recommended Posts

Hey,

I profiled 0ad with Very Sleepy and the following code path was causing the majority of my lag:

CCmpPathfinder::ProcessSameTurnMoves

CCmpPathfinder::ProcessLongRequests

CCmpPathfinder::ComputePath

ProcessNeighbour

(CalculateHeuristic, but it is not in the stack, as it is inlined)

isqrt64

The following patch basically eliminates this whole path from my profiles: https://gist.github.com/yeerkkiller1/b02d32c09e7f6c2685d9 .

Basically the CFixedVector2D is unnecessary, as is using any sort of sqrt. I changed it to just return the distance squared, which still appears to satisfy the constraints of the function (it is still a heuristic). I played with this a few times online with someone else that has the same change applied, and I didn't run into any issues with this change.

Lag will still occur with enough units, and the time is still spent in path finding, but the new bottleneck is inside ProcessShortRequests, ComputeShortPath, instead of ProcessLongRequests, ComputePath.

Is there a place (other than this forum) I can submit this patch for review?

Thanks!

--

yeerk

  • Like 1
Link to comment
Share on other sites

This and similar things have been proposed many times before. The problem is you are now using doubles, which aren't safe in the simulation, it must have identical behavior on all platforms. Fixed and sqrts only appear to be a bottleneck in profilers because the overall algorithm is quite flawed. (As far as using sqrt, I can't remember off the top of my head, but I seem to recall there is a good reason for it, you should discuss it with Philip on IRC, or maybe it's buried in a forum topic around here)

Link to comment
Share on other sites

This and similar things have been proposed many times before. The problem is you are now using doubles, which aren't safe in the simulation, it must have identical behavior on all platforms. Fixed and sqrts only appear to be a bottleneck in profilers because the overall algorithm is quite flawed. (As far as using sqrt, I can't remember off the top of my head, but I seem to recall there is a good reason for it, you should discuss it with Philip on IRC, or maybe it's buried in a forum topic around here)

I also seem to remember Philip finding issues with floating point. I think Redfox tried something along these lines as well?

Edited by WhiteTreePaladin
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...