Optimizing a build for size

    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.

    Disabling 3D

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

    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%.

    Disabling unwanted modules

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

    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:

    Godot 3.1 onwards allows to compile using size optimizations. To enable this, just set the flag to :

    Compiling with link-time optimization

    Enabling link-time optimization produces more efficient binaries, both in terms of performance and file size. It works by eliminating duplicate template functions and unused code. It can currently be used with the GCC and MSVC compilers:

    Linking becomes much slower with this option, so it should be used only for release builds.

    If you build from source, remember to strip debug symbols from binaries:

    Using UPX to compress binaries

    However, keep in mind that some antivirus programs may detect UPX-packed binaries as a virus. Therefore, if you are releasing a commercial game, make sure to sign your binaries or use a platform that will distribute them.