ビルドのサイズを最適化する¶
理由¶
時として、速度よりもサイズを重視して最適化したいこともあります。それには、エンジンの不必要な機能をコンパイルしないようにしたり、サイズ縮小に役立つ特定のコンパイラ フラグを用いることです。主に、モバイルやWebプラットフォーム向けのビルドをする場合が想定されます。
このチュートリアルでは、より小さなバイナリを作るための複数の方法を紹介していきます。先にすすむ前にまず、Godotをそれぞれのプラットフォームにコンパイルすることについてのチュートリアルを読むことをおすすめします。
参考
You can use the online
Godot build options generator
to generate a custom.py
file containing SCons options.
You can then save this file and place it at the root of your Godot source directory.
3Dの無効化¶
2Dゲームに3Dエンジン全体を持たせることは、通常あまり意味はありません。そのため、これを無効化するビルド フラグがあります:
scons p=windows target=release tools=no disable_3d=yes
エディタは3Dサポート無しで動くようには設計されていないため、このフラグを使うには、まず tools を無効にする必要があります。3Dの無効化により、バイナリのサイズはおよそ15%減ります。
高度なGUIノードの無効化¶
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
不要なモジュールの無効化¶
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_webp_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_webp_enabled = "no"
module_webrtc_enabled = "no"
module_websocket_enabled = "no"
module_xatlas_unwrap_enabled = "no"
スピードの代わりにサイズを最適化する¶
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のようないくつかのプラットフォームでは、標準でこのモードが有効になっています。
リンク時最適化を使用したコンパイル¶
リンク時最適化を有効にすると、パフォーマンスとファイルサイズの両方の点で、より効率的なバイナリが生成されます。重複するテンプレート関数と未使用のコードを排除することで機能します。現在、GCCおよびMSVCコンパイラで使用できます。
scons p=windows target=release tools=no use_lto=yes
このオプションではリンクが非常に遅くなるため、リリースビルドにのみ使用する必要があります。