optimizing_for_size.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. .. _doc_optimizing_for_size:
  2. Optimizing a build for size
  3. ===========================
  4. .. highlight:: shell
  5. Rationale
  6. ---------
  7. Sometimes, it is desired to optimize a build for size rather than speed.
  8. This means not compiling unused functions from the engine, as well as using
  9. specific compiler flags to aid on decreasing build size.
  10. Common situations include creating builds for mobile and Web platforms.
  11. This tutorial aims to give an overview on different methods to create
  12. a smaller binary. Before continuing, it is recommended to read the previous tutorials
  13. on compiling Godot for each platform.
  14. .. seealso::
  15. You can use the online
  16. `Godot build options generator <https://godot-build-options-generator.github.io/>`__
  17. to generate a ``custom.py`` file containing SCons options.
  18. You can then save this file and place it at the root of your Godot source directory.
  19. Disabling 3D
  20. ------------
  21. For 2D games, having the whole 3D engine available usually makes no sense. Because of this, there is a build flag to disable it:
  22. ::
  23. scons p=windows target=release tools=no disable_3d=yes
  24. Tools must be disabled in order to use this flag, as the editor is not designed
  25. to operate without 3D support. Without it, the binary size can be reduced
  26. by about 15%.
  27. Disabling advanced GUI nodes
  28. ----------------------------
  29. Most small games don't require complex GUI controls such as Tree, ItemList,
  30. TextEdit or GraphEdit. They can be disabled using a build flag:
  31. ::
  32. scons p=windows target=release tools=no disable_advanced_gui=yes
  33. Disabling unwanted modules
  34. --------------------------
  35. A lot of Godot's functions are offered as modules.
  36. You can see a list of modules with the following command:
  37. ::
  38. scons --help
  39. The list of modules that can be disabled will appear, together with all
  40. build options. If you are working on a simple 2D game, you could disable
  41. a lot of them:
  42. ::
  43. 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
  44. If this proves not to work for your use case, you should review the list of
  45. modules and see which ones you actually still need for your game (e.g. you
  46. might want to keep networking-related modules, regex support, or theora/webm
  47. to play videos).
  48. Alternatively, you can supply a list of disabled modules by creating
  49. ``custom.py`` at the root of the source, with the contents similar to the
  50. following:
  51. .. code-block:: python
  52. # custom.py
  53. module_arkit_enabled = "no"
  54. module_assimp_enabled = "no"
  55. module_bmp_enabled = "no"
  56. module_bullet_enabled = "no"
  57. module_camera_enabled = "no"
  58. module_csg_enabled = "no"
  59. module_dds_enabled = "no"
  60. module_enet_enabled = "no"
  61. module_etc_enabled = "no"
  62. module_gdnative_enabled = "no"
  63. module_gridmap_enabled = "no"
  64. module_hdr_enabled = "no"
  65. module_jsonrpc_enabled = "no"
  66. module_mbedtls_enabled = "no"
  67. module_mobile_vr_enabled = "no"
  68. module_opensimplex_enabled = "no"
  69. module_opus_enabled = "no"
  70. module_pvr_enabled = "no"
  71. module_recast_enabled = "no"
  72. module_regex_enabled = "no"
  73. module_squish_enabled = "no"
  74. module_svg_enabled = "no"
  75. module_tga_enabled = "no"
  76. module_theora_enabled = "no"
  77. module_tinyexr_enabled = "no"
  78. module_upnp_enabled = "no"
  79. module_vhacd_enabled = "no"
  80. module_vorbis_enabled = "no"
  81. module_webm_enabled = "no"
  82. module_webp_enabled = "no"
  83. module_webrtc_enabled = "no"
  84. module_websocket_enabled = "no"
  85. module_xatlas_unwrap_enabled = "no"
  86. .. seealso::
  87. :ref:`doc_overriding_build_options`.
  88. Optimizing for size instead of speed
  89. ------------------------------------
  90. Godot 3.1 onwards allows compiling using size optimizations (instead of speed).
  91. To enable this, set the ``optimize`` flag to ``size``:
  92. ::
  93. scons p=windows target=release tools=no optimize=size
  94. Some platforms such as WebAssembly already use this mode by default.
  95. Compiling with link-time optimization
  96. -------------------------------------
  97. Enabling link-time optimization produces more efficient binaries, both in
  98. terms of performance and file size. It works by eliminating duplicate
  99. template functions and unused code. It can currently be used with the GCC
  100. and MSVC compilers:
  101. ::
  102. scons p=windows target=release tools=no use_lto=yes
  103. Linking becomes much slower and more RAM consuming with this option, so it should be used only for
  104. release builds.
  105. Stripping binaries
  106. ------------------
  107. If you build from source, remember to strip debug symbols from binaries:
  108. ::
  109. strip godot.64