Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix map cache invalidation #31295

Merged

Conversation

kevingranade
Copy link
Member

@kevingranade kevingranade commented Jun 10, 2019

Summary

SUMMARY: Performance "Avoid recalculating vision and lightmap unnecessarily."

Purpose of Change

Fixes #31252
The recent change in #30018 made the overhead of calculating the vision and light caches during crafting and other long actions prohibitive.

Describe the solution

Uses the existing transparency cache code to decide when it's safe to skip regenerating the vision and lightmap caches.
Critically, removes several cache invalidations that were happening every turn which seem to be unnecessary.

Describe alternatives you've considered

"Make it faster". I'm working on it, but this is much faster for the scenario where the cache isn't being invalidated often.

Video

https://photos.app.goo.gl/tE7WijfYzgJaD4Fm9

@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Code: Performance Performance boosting code (CPU, memory, etc.) Time / Turns / Duration / Date Issues concerning any activities being too fast or too slow. Also issues about time and date ingame Z-levels Levels below and above ground. labels Jun 10, 2019
@ifreund
Copy link
Contributor

ifreund commented Jun 10, 2019

Didn't do any profiling, but can confirm that crafting is subjectively a good 5+ times faster with this PR applied.

@ZhilkinSerg ZhilkinSerg self-assigned this Jun 10, 2019
@kevingranade
Copy link
Member Author

@anothersimulacrum reported that picking up a light emitting object such as a flashlight fails to trigger a vision update.
I'm on the fence whether that (and the similar issues I'm certain this will also cause) is a worse problem than the poor performance while performing long actions.

@anothersimulacrum
Copy link
Member

anothersimulacrum commented Jun 11, 2019

I ran into a few more issues - one while playing with this, and two more while testing to get an easily reproducible case of the first one.

Here are the issues:
Flashlights work very oddly with this - they will only update (in an empty field) when you get to 3 or so tiles from the edge of their light radius.
There is no immediate visual feedback from turning on aisle lights in a car - you don't notice it until you get out and move around a bit so the vision updates.

Here's the one I encountered in gameplay:
While crafting all night long in a vehicle, the lighting did not update to show that it was day until I got out and walked around a bit - here's a save to show the issue.
test.zip
(craft as many bricks as you can and it will turn to day, but the map will not update to show that)

@kevingranade kevingranade force-pushed the fix-map-cache-invalidation branch from 4784b18 to da2f28b Compare June 11, 2019 03:15
@kevingranade
Copy link
Member Author

I revisited the cache invalidation logic for the lighting cache, and it needs significant additional infrastructure to work properly.
As such I backed out that part of the change, since it wasn't a major component of slowdown anyway, this addresses any issues that arose due to lighting.

@kevingranade kevingranade force-pushed the fix-map-cache-invalidation branch from da2f28b to 25f79b6 Compare June 11, 2019 07:56
@kevingranade kevingranade force-pushed the fix-map-cache-invalidation branch from 25f79b6 to 951503f Compare June 12, 2019 07:47
@ZhilkinSerg ZhilkinSerg merged commit 22e92fa into CleverRaven:master Jun 12, 2019
@ZhilkinSerg ZhilkinSerg removed their assignment Jun 12, 2019
@kevingranade kevingranade deleted the fix-map-cache-invalidation branch June 12, 2019 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Performance Performance boosting code (CPU, memory, etc.) Time / Turns / Duration / Date Issues concerning any activities being too fast or too slow. Also issues about time and date ingame Z-levels Levels below and above ground.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crafting takes a lot more real time now.
4 participants