-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Implement Feature Build Profiles #62996
Conversation
I would also include PCK encryption key into the same dialog / config file. Currently, it's set using environment variable, which is not a clear way to do it for many users.
It probably should have separate section for selecting |
Awesome work 🙂 In a future PR, it could be useful to expose the "detect from project" functionality as a command line argument, so you can run it automatically when using custom export templates for your project on CI on every commit. (That said, if you only intend to recompile your export templates occasionally, it may be better to generate the build profile once on your own machine instead and commit it to version control.) |
@Calinou I think it should be possible to do this without much effort, so you pass the .build file and it updates it. |
Is there any performance gain in the editor or in the game build when disabling features? |
No, run-time performance is expected to remain identical. |
@jcostello nope |
If we have automatic usage detection, wouldn't it be better to disable everything by default? If for some reason this is not the default, should we expect any issues from disabling everything manually to delegate it completely to the auto-detector?
How would this work with APIs like |
@neikeq auto-detect disables what is not used already by default. If you use ClassDB manually and somehow don't use the class, then it will not auto detect it. Put the classes you use in the bottom text edit so they are force detected. |
1a9d5b5
to
64579c8
Compare
"disable_2d_physics", | ||
"disable_3d_physics", | ||
"disable_navigation", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have these options yet, is that placeholders for future work?
We do have disable_advanced
gui` though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah they are placeholders, so eventually they need to be implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disable advanced gui kind of loses making much sense with this and should likely be removed as this feature does everything its supposed to do.
a597ac5
to
3fc7aa2
Compare
This PR is a continuation of godotengine#50381 (which was implemented exactly a year ago!) * Add a visual interface to select which classes should not be built into Godot (well, they are built if something else uses them, but if not used the optimizer will remove them out). * Add a detection system to scan the project and figure out the actual classes used. * Added the ability for SCons to load build profiles. Obligatory Screen: A simple test with a couple of nodes in the scene resulted in a 25% reduction for the final binary size TODO: * Script languages need to implement used class detection (left for another PR). * Options to disable servers or server functionalities (like 2D or 3D physics, navigation, etc). Are missing, that should also greatly aid in reducing binary size. * Options to disable some modules would be desired. * More options to disable drivers (OpenGL, Vulkan, etc) would be desired. In general this PR is a starting point for more contributors to improve and enhance this functionality.
3fc7aa2
to
6236a68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Thanks! |
What about load times? We're seeing 10s+ load times for HTML5 games on old devices and it'd be really amazing if this reduced it 🤞 Awesome work by the way 🙌 |
Load times will probably not improve by more than 10% or so, even with nearly all features disabled. Unfortunately, I don't know any other low-hanging fruits to reduce the WebAssembly bundle size. Remember that Godot is asking a lot from the browser, especially on old/low-end devices. Loading a WebAssembly payload that is 10+ MB is not an easy task for the browser. For old/low-end devices, native ports will always be a better experience. |
True, it is really impressive that Godot even runs in the browser on those old mobile devices.
Interesting. What makes up the bulk of the WebAssembly bundle size if it's not features? |
@bfelbo It is features. But disabling a feature in a build profile does not necessarily mean it will be not compiled. With the feature build profile system introduced in this PR, what it does is cause the classes to not be registered in ClassDB. Any code that isn't registered or referred to anywhere will be removed by the linker. However, a lot of the code will still be referred to anyway. For example, a Godot game must have Viewport, and Viewport depends on the Camera2D and Camera3D nodes. Even if those nodes are not registered with ClassDB, their code will still be included because Viewport needs those classes. @reduz summarizes this well in his post:
If you want to disable more of the engine, a more thorough approach than just not registering classes is needed. I have a PR that allows disabling 2D nodes, and I have another PR for moving 2D and 3D resources to subfolders so that they can be more easily disabled, but these have not been merged yet. To be clear, the ideal solution is a combination of this PR's approach of not registering classes, and my PRs for forcefully disabling parts of the engine. |
little feedback report, I tried this the other day and was able to reduce my ~57 mb master branch binary (release, linux 64 bit) to 40 mb. so that's really nice I think. I did took me quite a while though to manually compile a list of classes my project uses that the auto detect feature was not able to detect. it's probably not something that can be expected of the average user. also, is there any chance of this being backported to 3.x? for people wanting to optimize for size, this would be especially interesting to use with 3.x as it compounds with the already significantly smaller code base size. for instance, if Godot 3.x could rival Flutter in wasm size (~7mb) that would be pretty cool. |
@h0lley I don't think Godot 4 will be able to go down to 7 MB. My guess is we can get it down to 20 MB if we combine this PR with my other PRs and disabling modules and likely some more additional work. https://docs.google.com/spreadsheets/d/1aWmWiA6MWoHr4Mgg22tybDFPa6BJX5oHTSjfN21plyY/edit#gid=0 Here is a spreadsheet I made over a year ago, it should still be roughly accurate. A lot of the size is from the core folder, and that code can't / shouldn't be removed. I'm curious to see what the results would be if we recreated this spreadsheet with as many changes as we can to reduce the size, to see what's left as the biggest pieces. Anyway, this is getting off-topic for this PR. Feel free to contact me elsewhere and we can work on this together. |
This relies on a lot of backwards-incompatible changes, so I'm afraid not. |
I think you should open an issue if the auto-detect feature fails to detect a class you use. Unless the classes are accessed dynamically (via |
I believe only classes referenced in tscn and tres are detected atm, and nothing that's only in script.
so at least reduz is already aware.
right, having to add one or two classes in those very niche use-cases to the "forced classes on detect" field is by no means asked too much. for reference though, here's what I had to specify manually:
so yea, according to current auto detection apparently my project doesn't use MainLoop, for instance 😅 |
What about nowadays? :) |
you can use this to make very slim builds in terms of size, not so much for performance. |
This PR is a continuation of #50381 (which was implemented exactly a year ago!). I was too busy to finish this, but I really wanted it before Beta so it does not have to wait for 4.1.
Obligatory Screen:
Usage:
A simple test with a couple of nodes in the scene resulted in a 25% reduction for the final binary size. With the ability to disable more core parts of the engine, gains should be considerably even more dramatic.
TODO:
In general this PR is a starting point for more contributors to improve and enhance this functionality.