godot: Script classes make the CreateDialog search filter prohibitively slow
Godot version: Godot 3.1
Issue description: The CreateDialog is incredibly laggy (like, prohibitively laggy) when you have many script classes defined in your project and you try to type into the search filter.
Steps to reproduce:
- Create a new project.
- Download godot-next from GitHub, extract the .zip, and add the plugin.
- Turn the plugin on.
- Open the CreateDialog and try typing in the search field.
It will lag incredibly long.
Suggested solution:
I believe this is happening because of runtime checks that the CreateDialog has to perform to track inheritance relationships between script classes, as well as a host of additional logic that allows it to handle engine types, script classes, and custom types. Every time the text_changed signal of the TextEdit fires (so every add or delete of a character), it rebuilds the entire tree, even though none of the data is really changing.
Ideally, we should instead be able to not change any of the TreeItem structure, but toggle the display of certain ones. I’m not sure yet if that is a feature, but if not, we can add it, only update the visualization during text_changed, but rebuild the tree only when script classes have been updated by the EditorFileSystem. This will guarantee fast opening of the CreateDialog, and fast updating of the structure as users type text, resulting in a much more responsive tool.
Bugsquad edit (keywords for easier searching): named class, class_name
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 11
- Comments: 23 (15 by maintainers)
I had this issue back in 3.x and I continue having it on 4.1.
This is in an empty project, on an Intel Core i7-7700:
https://github.com/godotengine/godot/assets/5783414/609d1113-1da6-4ad4-9649-b7d8166b243d
This is with my current project, on an Intel Core i7-7700:
https://github.com/godotengine/godot/assets/5783414/77b115b8-1daa-4548-a412-db36dfafd6ec
And this is with my current project, on an AMD A10-7850K:
https://github.com/godotengine/godot/assets/5783414/5177f99d-8615-493c-953c-b15fb94b151b
I have a lot of scripts but certainly much less than 1500
And several of these do not have a class_name, so they don’t show up in the create node dialog.
I think a decent way to work around this in
3.xwould be to implement a dynamic debounce timer based on the time the last search took. If more than 0.3 seconds have elapsed between the keystroke was made and the tree was done updating, set the timer’s wait time to 0.25 seconds. By default, set the timer’s wait time to a low value like 0.05 seconds (just to ensure typing is always responsive enough, even on small projects).If anyone is interested on working on this, you can find an example of a LineEdit search field with a debounce timer here: https://github.com/godotengine/godot/pull/42402
I recommend opening a pull request against the
3.xbranch first, then we can look into forward-porting this to themasterbranch. The CreateDialog’s source code is here: https://github.com/godotengine/godot/blob/3.x/editor/create_dialog.cpp@willnationsdev I’m curious how much performance gains #27566 provided, I want to resolve this issue in 3.2, at least locally.
The searching part also has to be taken into account. Can easily take around 3-6 seconds just to find a class of interest, depending on the verbosity of a class name.
The merged PR #33387 did provide some performance improvement, but still too slow.
Having around 100 global scripts, Windows.
There are no parsing errors either which would affect this.
I’ve made this PR that doesn’t completely solve this issue, but improves the time it takes to update the tree (~2 times faster) so it makes the filter usable again: #33387