X Tutup
Skip to content

Avoid unnecessary updates in TileMapLayer #109243

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
precup:tile-map-optimizations
Sep 25, 2025
Merged

Avoid unnecessary updates in TileMapLayer #109243
Repiteo merged 1 commit intogodotengine:masterfrom
precup:tile-map-optimizations

Conversation

@precup
Copy link
Contributor

@precup precup commented Aug 2, 2025

Significantly improves #105957, although I'm not sure if it's fast enough to be considered fixed or not.

Looking at the flamegraph, there were two major sections that seemed like low hanging fruit.

The first was that if navigation_enabled is false, then any update will cause every cell to clear its navigation, which isn't needed if navigation wasn't already in use.

The second was a bunch of overhead from the red black tree used to sort quadrants. I tried out LocalVector and SortArray instead to see how it would compare, and it's uglier but significantly faster.

Numbers

With no optimizations, I get ~260 ms Physics spikes.
image

With the first optimization, I get 42 ms Physics spikes.
image

With both optimizations, I get 28 ms Physics spikes.
image

At that point, the process time dominates.

@precup precup requested a review from a team as a code owner August 2, 2025 16:09
@KoBeWi KoBeWi added this to the 4.x milestone Aug 2, 2025
@precup precup force-pushed the tile-map-optimizations branch 2 times, most recently from 9ecc131 to e67a6ec Compare August 4, 2025 15:21
@precup precup force-pushed the tile-map-optimizations branch from e67a6ec to adfb0d8 Compare August 4, 2025 18:07
@precup precup changed the title Optimize TileMapLayer::set_cell Avoid unnecessary updates in TileMapLayer Aug 4, 2025
@clayjohn clayjohn modified the milestones: 4.x, 4.6 Sep 25, 2025
@Repiteo Repiteo merged commit a078895 into godotengine:master Sep 25, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Sep 25, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup