Optimize TileMapLayerEditor#97091
Conversation
18d685a to
0214b87
Compare
b41b1c2 to
e7e615b
Compare
e7e615b to
b0c0163
Compare
|
@Nazarwadim Can you please rebase on master to prepare this for merging? Note that editor/plugins/tiles/tile_data_editors.cpp was renamed to editor/scene/2d/tiles/tile_data_editors.cpp. |
| @@ -545,6 +545,16 @@ bool TileSet::has_source(int p_source_id) const { | |||
| return sources.has(p_source_id); | |||
| } | |||
|
|
|||
| #ifdef TOOLS_ENABLED | |||
| TileSetSource *TileSet::get_source_ptr(int p_source_id) const { | |||
There was a problem hiding this comment.
Does this increase performance compared to the previous code?:
TileSetSource *source = nullptr;
if (tile_set->has_source(tile_source_id)) {
source = *tile_set->get_source(tile_source_id);
}
If not, I think it's a bit pointless to create a function just for that. And if it does improve performance, I think it should be fixed in many other places, not just here.
There was a problem hiding this comment.
We are slowly rooting out the "has/get" pattern throughout the codebase. It needlessly duplicates all the expensive parts of using a Hashmap. Literally doing the exact same expensive operation twice.
You can't really compare the old code to the new one here, since, after fixing the other issues has_source() becomes more of a bottleneck than it was in the original code.
What happens exactly is:
Before: the old code is so slow that you only get a few frames per second. So has_source() / get_source() appears insignificant
After: More frames are processed per second which multiplies the cost of has_source() / get_source() so cutting the combined cost in half ends up being worthwhile
There was a problem hiding this comment.
I mean, I am not against the idea of getting rid of the has_something / get_something pattern. It's just that this is used EVERYWHERE in the TileMap / TileSet and the respective editor code. If we go that route, I'd rather have it fixed everywhere rather than this single instance.
And this should be done for:
- sources
- atlas coords
- alternative tiles IDs
not sources only.
We can merge it as is if we consider this performance culprit a blocker. I just that I believe this specific optimization should be done consistently, for both performance and maintainability.
There was a problem hiding this comment.
That optimization should be done consistently but it isn't a reason to stall this PR. This PR has significant improvements for anyone working with TileMapLayer(s) of non-trivial sizes.
|
The main problem in this code is indeed the use of |
Take a look at the profiling results I posted above 32% of the cost of the function is from calling |
I mean, the PR does not remove the call to |
I can think of a couple reasons, but what I think is most likely is the |
Hmm I don't know. I'll make a branch just removing |
|
Ok, I made this branch: https://github.com/groud/godot/tree/remove_get_used_cells @clayjohn if you wanna try it out :) |
|
@groud Here you go!
I highly recommend getting comfortable with a profiler yourself. It helps you build intuition for where changes will actually benefit performance. Importantly, it means you no longer have to guess. |
Sorry, since I needed to test three setup (as we don't have the same machine) I was a bit a lazy on that one. But you're right :p But alright. I guess the change is quite efficient then. If we think we don't need to fix the issue everywhere right now, the PR is fine (beside the small double-check I mentioned) |
b0c0163 to
4ea6aa4
Compare
4ea6aa4 to
61df783
Compare
|
I fixed the bottleneck |
389836b to
e7a4344
Compare
|
If ground has no objections, I think it could be merged after a rebase |
Yeah, I don't think I like it's that much, as it only fixes the the issue in one specific instance. But well, it's probably the most annoying one, so let's go for it. Once rebased I think it can be merged. |
|
I'm not sure if @Nazarwadim is available to do the rebasing (they have had little activity over the past few months, and this PR is 1.5 years old). I've gone ahead and rebased [and squashed] it here https://github.com/Shadows-of-Fire/godot-engine/tree/opt-tilemaplayer-editor The actual rebase was a trivial indentation change in the last hunk of I can either make a PR from my rebased branch that points to this one, or if this maintainers are able to edit Nazar's source branch you can push the rebase there and we can continue on this PR. |
|
@Shadows-of-Fire I willl rebase this soon |
|
@Nazarwadim Do you have any idea of when you'll be available for this? If you don't have time I can just open another PR from my rebased branch. I'm hoping to avoid the need for more rebases and also avoid a slip from the next release. |
e7a4344 to
2eb428a
Compare





Before:
before.mp4
After:
after.mp4