ビルドのサイズを最適化する¶
理由¶
時として、速度よりもサイズを重視して最適化したいこともあります。それには、エンジンの不必要な機能をコンパイルしないようにしたり、サイズ縮小に役立つ特定のコンパイラ フラグを用いることです。主に、モバイルやWebプラットフォーム向けのビルドをする場合が想定されます。
このチュートリアルでは、より小さなバイナリを作るための複数の方法を紹介していきます。先にすすむ前にまず、Godotをそれぞれのプラットフォームにコンパイルすることについてのチュートリアルを読むことをおすすめします。
The options below are listed from the most important (greatest size savings) to the least important (lowest size savings).
バイナリの除去¶
Space savings: Very high
Difficulty: Easy
Performed in official builds: Yes
If you build Windows (MinGW), Linux or macOS binaries from source, remember to
strip debug symbols from binaries by installing the strip
package from your
distribution then running:
strip path/to/godot.binary
On Windows, strip.exe
is included in most MinGW toolchain setups.
This will reduce the size of compiled binaries by a factor between 5× and 10×. The downside is that crash backtraces will no longer provide accurate information (which is useful for troubleshooting the cause of a crash). C++ profilers will also no longer be able to display function names (this does not affect the built-in GDScript profiler).
注釈
The above command will not work on Windows binaries compiled with MSVC
and platforms such as Android and HTML5. Instead, pass debug_symbols=no
on the SCons command line when compiling.
スピードの代わりにサイズを最適化する¶
Space savings: High
Difficulty: Easy
Performed in official builds: Yes, but only for HTML5
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
WebAssemblyのようないくつかのプラットフォームでは、標準でこのモードが有効になっています。
リンク時最適化を使用したコンパイル¶
Space savings: High
Difficulty: Easy
Performed in official builds: Yes
リンク時最適化を有効にすると、パフォーマンスとファイルサイズの両方の点で、より効率的なバイナリが生成されます。重複するテンプレート関数と未使用のコードを排除することで機能します。現在、GCCおよびMSVCコンパイラで使用できます。
scons p=windows target=release tools=no lto=full
Linking becomes much slower and more RAM-consuming with this option, so it should be used only for release builds:
When compiling the
master
branch, you need to have at least 8 GB of RAM available for successful linking with LTO enabled.When compiling the
3.x
branch, you need to have at least 6 GB of RAM available for successful linking with LTO enabled.
3Dの無効化¶
Space savings: Moderate
Difficulty: Easy
Performed in official builds: No
2Dゲームに3Dエンジン全体を持たせることは、通常あまり意味はありません。そのため、これを無効化するビルド フラグがあります:
scons p=windows target=release tools=no disable_3d=yes
エディタは3Dサポート無しで動くようには設計されていないため、このフラグを使うには、まず tools を無効にする必要があります。3Dの無効化により、バイナリのサイズはおよそ15%減ります。
Disabling advanced GUI objects¶
Space savings: Moderate
Difficulty: Easy
Performed in official builds: No
Most small games don't require complex GUI controls such as Tree, ItemList, TextEdit or GraphEdit. They can be disabled using a build flag:
scons p=windows target=release tools=no disable_advanced_gui=yes
This is everything that will be disabled:
FileDialog
PopupMenu
Tree
TextEdit
TreeItem
OptionButton
SpinBox
ColorPicker
ColorPickerButton
RichTextLabel
RichTextEffect
CharFXTransform
PopupDialog
WindowDialog
AcceptDialog
ConfirmationDialog
MarginContainer
ビューポートコンテナ
SplitContainer
HSplitContainer
GraphNode
GraphEdit
不要なモジュールの無効化¶
Space savings: Very low to moderate depending on modules
Difficulty: Medium to hard depending on modules
Performed in official builds: No
Godotの機能の多くはモジュールとして提供されています。モジュールのリストを見るには、次のコマンドを使います:
scons --help
無効にできるモジュールのリストが、ビルドオプションと共に表示されます。シンプルな2Dゲームであれば、このうちの多くを無効にできます:
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
これがあなたの事例に合わなかった場合、もういちどモジュールのリストを見直して、どれがまだゲームに必要なのか確認してください (たとえば、ネットワーク関連のモジュールや、正規表現サポート、あるいはビデオ再生のためにtheora/webmを残しておきたいかもしれません)。
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"
参考
:ref:'doc_overriding_build_options'。