Optimizing a build for size

Rationale

Sometimes, it is desired to optimize a build for size rather than speed. This means not compiling unused functions from the engine, as well as using specific compiler flags to aid on decreasing build size. Common situations include creating builds for mobile and Web platforms.

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.

The options below are listed from the most important (greatest size savings) to the least important (lowest size savings).

Stripping binaries

  • 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).

Note

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.

Optimizing for size instead of speed

  • 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=template_release optimize=size

Some platforms such as WebAssembly already use this mode by default.

Disabling 3D

  • Space savings: Moderate

  • Difficulty: Easy

  • Performed in official builds: No

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

scons p=windows target=template_release disable_3d=yes

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 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=template_release disable_advanced_gui=yes

This is everything that will be disabled:

  • FileDialog

  • PopupMenu

  • Tree

  • TextEdit

  • CodeEdit

  • SyntaxHighlighter

  • CodeHighlighter

  • TreeItem

  • OptionButton

  • SpinBox

  • ColorPicker

  • ColorPickerButton

  • RichTextlab