Page 1 of 1

[1.1.74] Pathfinder is slow when landfilling

Posted: Thu Jan 05, 2023 8:48 am
by ILLISIS
Hi

I have been speaking to Klonan about this issue in Discord.

How I came about this issue was I noticed the pathfinder was taking extremely long to find a path when I was testing my path retry settings for Constructron-Continued. Klonan was right to think it was the retry system / mod code and I couldn't disagree so I spent a couple of days overhauling my code and searching for the bug to no avail.

The main thing I noticed that pushed me to report this as a bug was that I was absolutely sure that there was one "entry point" function which requested a path and placing a break point in that function triggered nothing when the pathfinder would continuously try to get from A to B but not fire the event handler or fail but instead continuously try over and over.

Issue in action:
https://youtu.be/fisKp7d1mx8?t=30
https://youtu.be/fisKp7d1mx8?t=100

I recommend watching the above at 0.25x speed.

You can definitely attribute SOME pathfinder requests to the retry system I agree.
But on the second link at ~1:40 there is a VERY distinct difference that causes well over 50 path attempts(not via lua code retry's) for it to finally 'finish'.

Same can be seen at ~2:40 https://youtu.be/fisKp7d1mx8?t=158
Interestingly when I zoom in on this and the path resolution modifier already looks to be set at 0 instead of -2 which is exactly what retry attempt 5 does in my code.

My theory is that this looks like the pathfinder itself is struggling to find a path but also doesn't want to abort and fire on_script_path_request_finished.

To test this theory, I set the path resolution modifer and bouding_box to be the smallest size on the initial request(instead of using retry system) and setup the spider remote to trigger the pathfinder. I witnessed the same seizure behavior though not to the same extent at first but when you start building landfill the problem grows exponentially worse. Before/after video: https://www.youtube.com/watch?v=KqkTg0oKeXk

My only conclusion is that I have found some kind of edge case in the pathfinder that when tiles change, causes some kind of reset or loop in the pathfinder.

Re: [1.1.74] Pathfinder is slow when path starts on landfill

Posted: Thu Jan 05, 2023 3:26 pm
by Loewchen
Post save file, log and steps that produce the issue please, see 3638.

Re: [1.1.74] Pathfinder is slow when path starts on landfill

Posted: Sat Jan 07, 2023 1:49 am
by ILLISIS
Load into map
Verify that pre-configured remote triggers the path finder.
Try to get to the left most large island like in the videos - should work fine
Rotate the inserter to activate the construction bots to build the landfill
Wait a short time
Try to get to the left most large island from where you are standing like in the videos - fails fairly consistently.

Re: [1.1.74] Pathfinder is slow when landfilling

Posted: Sat Jan 07, 2023 6:00 pm
by Rseding91
Thanks for the report. As far as I can tell this is working as intended. Any time a tile on a chunk the path finder is using is changed that path-find using that chunk is restarted. This is because the path finder does not know if changing that tile will make a brand new better path or invalidate the path it had already made into that chunk.

Re: [1.1.74] Pathfinder is slow when landfilling

Posted: Sat Jan 07, 2023 10:43 pm
by ILLISIS
Hi Rseding91!

If I may, I would like to propose that an incremental update occur to the chunk that changed instead after the remainder of the path is found. i.e; A small incremental check to go from the last point on the previous tile to the first point on the next tile. This would assume that this is the only available/fastest way there even if two land masses were joined by landfill but that is much less noticeable than a player entity using the pathfinder doing nothing for the duration of the intersecting chunk changes.

Additionally, this raises the question, what happens after a path is found and a chunk changes? This would normally be okay as in the base game players cannot add water for example. Entities and biters collide but I guess that looks fairly smooth when they encounter something that wasn't meant to be there from the player.