optimizing_for_size.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. Disabling 3D
  15. ------------
  16. For 2D games, having the whole 3D engine available usually makes no sense. Because of this, there is a build flag to disable it:
  17. ::
  18. scons p=windows target=release tools=no disable_3d=yes
  19. Tools must be disabled in order to use this flag, as the editor is not designed
  20. to operate without 3D support. Without it, the binary size can be reduced
  21. by about 15%.
  22. Disabling advanced GUI nodes
  23. ----------------------------
  24. Most small games don't require complex GUI controls such as Tree, ItemList,
  25. TextEditor or GraphEdit. They can be disabled using a build flag:
  26. ::
  27. scons p=windows target=release tools=no disable_advanced_gui=yes
  28. Disabling unwanted modules
  29. --------------------------
  30. A lot of Godot's functions are offered as modules.
  31. You can see a list of modules with the following command:
  32. ::
  33. scons --help
  34. The list of modules that can be disabled will appear, together with all
  35. build options. If you are working on a simple 2D game, you could disable
  36. a lot of them:
  37. ::
  38. scons p=windows target=release tools=no module_bmp_enabled=no module_bullet_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_mbedtls_enabled=no module_mobile_vr_enabled=no module_opus_enabled=no module_pvr_enabled=no module_recast_enabled=no module_regex_enabled=no module_squish_enabled=no module_tga_enabled=no module_thekla_unwrap_enabled=no module_theora_enabled=no module_tinyexr_enabled=no module_vorbis_enabled=no module_webm_enabled=no module_websocket_enabled=no
  39. Optimizing for size instead of speed
  40. ------------------------------------
  41. Godot 3.1 onwards allows to compile using size optimizations.
  42. To enable this, just set the ``optimize`` flag to ``size``:
  43. ::
  44. scons p=windows target=release tools=no optimize=size
  45. Some platforms such as WebAssembly already use this mode by default.
  46. Compiling with link-time optimization
  47. -------------------------------------
  48. Enabling link-time optimization produces more efficient binaries, both in
  49. terms of performance and file size. It works by eliminating duplicate
  50. template functions and unused code. It can currently be used with the GCC
  51. and MSVC compilers:
  52. ::
  53. scons p=windows target=release tools=no use_lto=yes
  54. Linking becomes much slower with this option, so it should be used only for
  55. release builds.
  56. Stripping binaries
  57. ------------------
  58. If you build from source, remember to strip debug symbols from binaries:
  59. ::
  60. strip godot.64
  61. Using UPX to compress binaries
  62. ------------------------------
  63. If you are targeting desktop platforms, the
  64. `UPX <https://upx.github.io/>`_ compressor can be used.
  65. This can reduce binary size considerably.
  66. However, keep in mind that some antivirus programs may detect UPX-packed
  67. binaries as a virus. Therefore, if you are releasing a commercial game,
  68. make sure to sign your binaries or use a platform that will distribute them.