-
Notifications
You must be signed in to change notification settings - Fork 68
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
Long loading time with large shapes #119
Comments
Here is the profiler graph when loading the scene, we can see the Process time at 4424ms which cause the freeze when loading the scene. Going step by step, I see that it is the SmartShape2D/addons/rmsmartshape/shapes/shape_base.gd Lines 1440 to 1632 in 3bc77ac
|
IIRC this topic came up on discord a while a go but I think nobody further investigated the problem. My guess is that it might be related to threading in SmartShape2D/addons/rmsmartshape/shapes/shape_base.gd Lines 1054 to 1063 in 3bc77ac
Can you try to add a You can also try to comment out the threading related lines (1056 - 1060) and add |
Thanks for your response, I'll test this out asap (probably tomorrow) and get back to you with the result. If this solves the problem, should I submit a PR that removes the threading? Or should I redo the threads management? I'm rather new contributing on GitHub but I would be glad to help |
If it actually solves the problem, we can discuss with the other contributors, whether to remove threaded computation or refactor it. This in turn requires further testing where the culprit lies exactly. |
I was able to test what you suggested @mphe : By adding the Also, replacing the threads by a direct call like below, the loading time is worse, I go from 5 seconds to 10:
|
Ok, good to know that threading is not a problem. Could you please provide an actual minimal reproduction project and not a a whole game project? |
I cleaned up the next branch to leave only the necessary (it was not the case at the beginning): it is no longer a complete game, only two scenes are left: a starting scene with just a button to load the level scene. In these two, I left the bare minimum, only the smart shapes remains in the level. Will it works for you? |
Ah, I'm sorry, I cloned the repo but forgot to switch the branch. Yes, it's fine. I'll try to look into it in the next days. |
Around 3 seconds here (main branch).
Here's the benchmark code I used:
|
I looked into it and timed various parts of the process and the case is clear. The edge generation code is simply an utter mess. Unfortunately, fixing the performance would require carefully refactoring and optimizing large parts of the generation process, which is not trivial and requires quite a bit of time and effort. |
Thank you for your time and deep analysis @mphe. 30-40% is a good first step to improve the overall performances. It might be interesting to merge it and then iterate to improve step by step. What can I do to help? I don't know how the edge generation code works but I'm ready to learn! |
Read the source and try to roughly understand how the plugin works. |
Nice! Should also improve editing performance which hasn't been stellar so far. Also wanted to mention that the mesh could be cached and saved in scene file during generation and simply rendered at runtime. Are there good reasons not to do it? |
Isn't that what @remorse107 has been working on? |
I believe so. There were some issues with this approach, but if it proves to be a feasible option, it might help address the loading time problem (although it won't resolve the performance issues with the editor). |
I initiated another pull request with some other performance improvements: #122 During my tests, I noticed an additional improvement of ~25%. Note: this is a draft PR, I don't have much time to work on it at the moment, I won't be able to complete this performance refactoring for now. |
Is this issue still relevant? Could somebody who had issues with long loading times test the latest version from GitHub? |
I've just tested the test project from top post with |
Hi, thanks for bringing attention to this issue. I'm no longer working with SmartShape2D or Godot. The PR is a draft, I think it needs little adjustments but serious tests/checks from an expert. I lack expertise and time to do that. From what I remember, the PR is "almost stable", all tests pass. The mentioned failing tests are related to a change suggestion that is not included in the PR changes, just a comment suggestion if someone wants to explore the improvement. |
Ah alright, thank you for the work you put into this! |
Context:
Version: 3bc77ac
Godot version: 4.0.2
Issue:
I encounter long loading times, from 5 to 15 seconds depending on the computer, when loading a scene with large shapes (mainly SS2D_Shape_Closed). This happens when opening the scene in the editor or when loading the scene in game.
I have about ten shapes with a total of 1024 points spread over an area of 32,000x32,000px. Most of them have curved edges. All shapes have a shape material and most of them have multiple textures (edge or fill).
If I remove the shape material from all these shapes, I no longer have a performance issue.
Here is an example of one of the ten shapes:
I can upload more configuration screenshots if needed.
How to reproduce:
I have made a branch on my project and clean up the code for a minimal reproduction:
https://github.com/martinboue/ludum-dare-53/tree/smart-shape-performance
You can start the project and click "Load level". The problematic scene can be found at "res://src/level/level.tscn".
Suggestions
Is there anything I can do differently on my side to improve performance?
Smart Shape seems to do some calculations when loading, could these calculations be saved/cached?
Thanks!
EDIT: I'm ready to work on a PR if needed, but I would need some help to go in the right direction (I don't know how the addon works internally)
The text was updated successfully, but these errors were encountered: