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

'Save before running' option in editor can greatly affect the speed of starting a run #78753

Open
univeous opened this issue Jun 27, 2023 · 8 comments · May be fixed by #90034
Open

'Save before running' option in editor can greatly affect the speed of starting a run #78753

univeous opened this issue Jun 27, 2023 · 8 comments · May be fixed by #90034

Comments

@univeous
Copy link
Contributor

Godot version

4.1 beta3

System information

Windows 11

Issue description

I've recently found the startup of running projects to be unbearably slow. Sometimes the editor would hang for like ~40s from the time I pressed the run button until I saw the actual game window.
After doing some research, I found that if I didn't have any of the scenes open in the editor, then I would get instantaneous startup speeds. The more scenes that are open in the editor, the slower it is to start the game.
I further found that disabling the 'save before running' option would give me almost the same startup speed as not having any scenes open while having a large number of scenes open.
I find it strange that even if none of the scenes have changed, enabling the 'save before running' option will save them all over again. I guess this affects the speed of the startup. I think it might be better to skip saving scenes that haven't changed.

no scene opened:
Godot_v4 1-beta3_win64_hzXmzFfllc

9 scenes opened and 'Save before running' on (~30s):
Godot_v4 1-beta3_win64_8ijcaF5Z0r

9 scenes opened and 'Save before running' off:
Godot_v4 1-beta3_win64_smMKD2tYpm

There are some gif compression issues, but I think they are enough to illustrate what I mean.

Steps to reproduce

  1. Open a large number of more complex scenes in the editor
  2. Make sure the 'Save before running' option is enabled in the editor settings
  3. Run the game
  4. Watch the editor hangs

Minimal reproduction project

N/A
In a small project, it may not make a significant difference, so it is difficult to produce an MRP.

@Calinou
Copy link
Member

Calinou commented Jun 28, 2023

What are the file sizes of the scene files currently open in the editor? If they take a while to save, they may contain embedded binary data which slows down saving and loading. Move this binary data to external .res files instead of embedding them in the .tscn file.

I think it might be better to skip saving scenes that haven't changed.

The reason we don't do this is that the "dirty" marking isn't 100% reliable: godotengine/godot-proposals#2153

@univeous
Copy link
Contributor Author

What are the file sizes of the scene files currently open in the editor?

They are all pretty small, none of them is bigger than 300KB. It doesn't make such a huge difference after I restart my computer, but the difference is still noticeable.

@isaaccp
Copy link
Contributor

isaaccp commented Jan 10, 2024

I had this happen to me over the course of a week and nearly drove me insane :D

I ended up building the editor with loads of debugging info until I found out what was going on.

I had 57 scenes open and you can see each of them takes 300ms to save:
image-3

Given that it seems like Godot knows which scenes need saving (as they show a * on the tab), can we just save the ones that are modified?

Alternatively, can we at least warn the user in some way (e.g. if you have more than 10 tabs open, warn when pressing Play or something), it caused me a full week of frustration until I debugged it :D

Or some indicator of what's happening, there was no feedback at all about what's going on.

A message saying "saving scenes" with the names of the scenes going by as they are saved would have clued me in much faster :)

Or at least add print_verbose() in save_scene() so running the editor with --verbose would let you see what's happening.

@Calinou
Copy link
Member

Calinou commented Jan 10, 2024

Given that it seems like Godot knows which scenes need saving (as they show a * on the tab), can we just save the ones that are modified?

See my above comment: #78753 (comment)

A message saying "saving scenes" with the names of the scenes going by as they are saved would have clued me in much faster :)

You can see a progress dialog when scenes are saving, regardless of what triggered the save.

PS: In the future, please use the Edit button (located behind the icon in the top-right corner of your comments) instead of multi-posting.

@isaaccp
Copy link
Contributor

isaaccp commented Jan 11, 2024

Given that it seems like Godot knows which scenes need saving (as they show a * on the tab), can we just save the ones that are modified?

See my above comment: #78753 (comment)

Whoops, not sure how I missed that comment :)

A message saying "saving scenes" with the names of the scenes going by as they are saved would have clued me in much faster :)

You can see a progress dialog when scenes are saving, regardless of what triggered the save.

The dialog doesn't show up during the long ~45 second wait, only for ~1 second at the very end. Maybe that's a regression?

This is a screen recording with less scenes loaded that only takes ~10 seconds or so what you can still see that the dialog only shows at the very end:

autosave_on_load_no_dialog_until_end

PS: In the future, please use the Edit button (located behind the icon in the top-right corner of your comments) instead of multi-posting.

Thanks, done!

Update: I looked at the code and it looks like the EditorProgress is only shown in _save_scene_with_preview():

EditorProgress save("save", TTR("Saving Scene"), 4);

And we only call _save_scene_with_preview() for the scene currently being edited:

if (i != editor_data.get_edited_scene()) {

In my case, I had 56 scenes to save through without any indication at all, and only when it reached the 57th quickly showed the save dialog.

@rainlizard
Copy link
Contributor

rainlizard commented Jan 26, 2024

This slows down compilation time a lot. It's a shame that it's going unnoticed since it only affects people with larger projects.

The solution is to make it skip saving the scenes that haven't been edited, but yeah it looks like that's not easy.

@sketchyfun
Copy link
Contributor

sketchyfun commented May 2, 2024

I've just come across this post while investigating why my game sometimes takes ages to start and then takes ages for the editor to become responsive after I close the game. Sometimes it takes a few seconds, sometimes it takes 20+ seconds. As soon as I turned off the 'save before running' option, the game started up instantly, and the editor was also responsive straight away when I closed the game. The strange thing is, if I manually save my game before running it, it only takes a second or two, so the actual saving of the scene(s) doesn't appear to be the issue. I tried running the editor with the --verbose flag to see exactly what was going on, and the bottleneck appeared to be the generation of previews for various files, usually materials. I think this might be a red herring though, as I tried modifying the engine so that the preview generation was skipped, and the editor still took a long time to start/stop the game, and the verbose output didn't display anything suspicious either. So I guess my question would be: what exactly is the auto save feature doing that manual saving isn't?

@ydeltastar
Copy link
Contributor

ydeltastar commented Jun 19, 2024

The strange thing is, if I manually save my game before running it, it only takes a second or two, so the actual saving of the scene(s) doesn't appear to be the issue.

Saving resources is fast, especially on SSDs, as they are usually small. The problem is that it triggers slow tasks after they are saved, some of them multiple times without need. From the source, it looks like many of the resource editors don't have a mechanism to track, save, and update only the changed so auto-saving causes redundancy and performance-intensive things to happen all at once.

Most of the slow-down in my project is caused by updating the script data: #92914

@KoBeWi KoBeWi linked a pull request Jun 24, 2024 that will close this issue
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.

6 participants