Einen Build für die Größe optimieren


Sometimes, it is desired to optimize a build for size rather than speed. This means not compiling unused functions from the engine, as well as using specific compiler flags to aid on decreasing build size. Common situations include creating builds for mobile and Web platforms.

This tutorial aims to give an overview on different methods to create a smaller binary. Before continuing, it is recommended to read the previous tutorials on compiling Godot for each platform.

Siehe auch

Sie können den Online Godot Bau-Options Generator nutzen, um eine custom.py Datei zu erzeugen, welche die SCons Optionen beinhaltet. Dann kann diese Datei im Wurzelverzeichnis von Godot gespeichert werden.

3D abschalten

For 2D games, having the whole 3D engine available usually makes no sense. Because of this, there is a build flag to disable it:

scons p=windows target=release tools=no disable_3d=yes

Tools must be disabled in order to use this flag, as the editor is not designed to operate without 3D support. Without it, the binary size can be reduced by about 15%.

Deaktivieren erweiterter GUI-Nodes

Die meisten kleinen Spiele benötigen keine komplexen GUI Kontroll-Elemente wie Tree, ItemList, TextEdit or GraphEdit. Sie können abgeschaltet werden mit einem Build Flag:

scons p=windows target=release tools=no disable_advanced_gui=yes

Unerwünschte Module deaktivieren

A lot of Godot's functions are offered as modules. You can see a list of modules with the following command:

scons --help

The list of modules that can be disabled will appear, together with all build options. If you are working on a simple 2D game, you could disable a lot of them:

scons p=windows target=release tools=no module_arkit_enabled=no module_assimp_enabled=no module_bmp_enabled=no module_bullet_enabled=no module_camera_enabled=no module_csg_enabled=no module_dds_enabled=no module_enet_enabled=no module_etc_enabled=no module_gdnative_enabled=no module_gridmap_enabled=no module_hdr_enabled=no module_jsonrpc_enabled=no module_mbedtls_enabled=no module_mobile_vr_enabled=no module_opensimplex_enabled=no module_opus_enabled=no module_pvr_enabled=no module_recast_enabled=no module_regex_enabled=no module_squish_enabled=no module_svg_enabled=no module_tga_enabled=no module_theora_enabled=no module_tinyexr_enabled=no module_upnp_enabled=no module_vhacd_enabled=no module_vorbis_enabled=no module_webm_enabled=no module_webrtc_enabled=no module_websocket_enabled=no module_xatlas_unwrap_enabled=no

If this proves not to work for your use case, you should review the list of modules and see which ones you actually still need for your game (e.g. you might want to keep networking-related modules, regex support, or theora/webm to play videos).

Alternatively, you can supply a list of disabled modules by creating custom.py at the root of the source, with the contents similar to the following:

# custom.py

module_arkit_enabled = "no"
module_assimp_enabled = "no"
module_bmp_enabled = "no"
module_bullet_enabled = "no"
module_camera_enabled = "no"
module_csg_enabled = "no"
module_dds_enabled = "no"
module_enet_enabled = "no"
module_etc_enabled = "no"
module_gdnative_enabled = "no"
module_gridmap_enabled = "no"
module_hdr_enabled = "no"
module_jsonrpc_enabled = "no"
module_mbedtls_enabled = "no"
module_mobile_vr_enabled = "no"
module_opensimplex_enabled = "no"
module_opus_enabled = "no"
module_pvr_enabled = "no"
module_recast_enabled = "no"
module_regex_enabled = "no"
module_squish_enabled = "no"
module_svg_enabled = "no"
module_tga_enabled = "no"
module_theora_enabled = "no"
module_tinyexr_enabled = "no"
module_upnp_enabled = "no"
module_vhacd_enabled = "no"
module_vorbis_enabled = "no"
module_webm_enabled = "no"
module_webrtc_enabled = "no"
module_websocket_enabled = "no"
module_xatlas_unwrap_enabled = "no"

Optimieren auf Größe statt Geschwindigkeit

Godot 3.1 onwards allows compiling using size optimizations (instead of speed). To enable this, set the optimize flag to size:

scons p=windows target=release tools=no optimize=size

Einige Plattformen wie z.B. WebAssembly verwenden diesen Modus bereits standardmäßig.

Binärdateien entfernen

Denken Sie beim Erstellen aus dem Quellcode daran, Debug-Symbole aus den Binärdateien zu entfernen:

strip godot.64