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

Very noticeable performance issues when adding nodes to a scene that contains many scripted nodes (editor) #78295

Closed
limbonaut opened this issue Jun 15, 2023 · 12 comments · Fixed by #78670

Comments

@limbonaut
Copy link
Contributor

limbonaut commented Jun 15, 2023

Godot version

Godot 4.1-beta2

System information

Manjaro Gnome, Intel Core i7-11800H

Issue description

On a relatively modern laptop (Intel Core i7-11800H), in a scene with many scripted nodes (total of 900+ with roughly half of them scripted), adding or duplicating a node freezes the editor for several seconds. Godot 4.0.2 handles such scenes much better!

Here is a flame graph captured while repeatedly duplicating simple Marker2D nodes with Ctrl+D in a complicated scene:
Screenshot from 2023-06-15 23-54-38

Performance data file to use with hotspot v1.4.1 (relevant data starts at the 75-second mark and lasts about 20+ seconds):
perf.data.perfparser.zip

Steps to reproduce

  1. Add 1000 nodes with a script attached.
  2. Duplicate a node and witness lags.

Also affects scrolling the scene tree dock.

Minimal reproduction project

add_node_lags_repro.zip

@Calinou
Copy link
Member

Calinou commented Jun 15, 2023

If you can compile the engine from source, you could look into bisecting the regression to greatly speed up troubleshooting.

Given the presence of EditorNode::_get_class_or_script_icon(), I'm guessing this has to do with #75472. I still recommend bisecting to check whether this is actually the case though.

@Calinou Calinou added this to the 4.1 milestone Jun 15, 2023
@akien-mga
Copy link
Member

CC @YuriSizov @KoBeWi

@KoBeWi
Copy link
Member

KoBeWi commented Jun 16, 2023

Sounds similar to #60127
Script icons are already cached, but _get_class_or_script_icon() doesn't fully utilize the cache probably.

@YuriSizov
Copy link
Contributor

EditorData is responsible for caching all the information about scripts, and from the chart in the OP I can see that its methods get hit, but then continue into the GDScript module. Which means there were no cache entries for the scripts that it tried to check.

Also keep in mind that EditorNode::_get_class_or_script_icon is called for any type, including built-in types which are fetched directly from the theme. So it's going to be called a lot regardless of the scripted classes. But I don't believe that the changes made to it significantly modify the logic compared to 4.0.x.

@limbonaut
Copy link
Contributor Author

limbonaut commented Jun 16, 2023

Just to be clear, the simple reproduction project performs much faster in 4.0.2. There are no noticeable lags. Removing scripts from the nodes also reduces lags by a big margin.
EDIT: will try to bisect the issue today.

@limbonaut
Copy link
Contributor Author

9fae654 is the first bad commit

@YuriSizov YuriSizov self-assigned this Jun 16, 2023
@sketchyfun
Copy link
Contributor

I've noticed this in my game too. Whenever I move a 3D object in the editor, it freezes for about a second. It definitely seems related to this script issue, as I was able to recreate the issue in a new scene with lots of duplicated nodes. The issue persisted until I finally tried removing the attached scripts, and then suddenly the issue went away.

@naturally-intelligent
Copy link

Just chiming in to say that I experience this with opening/switching to any large-ish scenes, which takes about 10 seconds in 4.1 and was nearly instant in 4.0. So I've stuck with 4.0.3. The issues for me started with 4.1-dev4.

@ValorZard
Copy link

Will this be solved for the 4.1 release?

@KoBeWi
Copy link
Member

KoBeWi commented Jun 25, 2023

I think the problem is here:

if (_script_icon_cache.has(p_script) && _script_icon_cache[p_script].is_valid()) {

Before #75472 the icon could get cached as null and the script wouldn't be re-parsed, but that's not true anymore.

EDIT:
Fixing this is not enough.

@limbonaut
Copy link
Contributor Author

I can confirm that #78670 improves performance. It is still worse than in version 4.0.2; however, the performance improvements are considerable and position it closer to 4.0.2 than beta 3.

@naturally-intelligent
Copy link

4.1-rc1 has eliminated the slowdown for me! :)

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

Successfully merging a pull request may close this issue.

8 participants