Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

Optimizando una compilación para reducir el tamaño

Fundamentos

A veces, se desea optimizar una compilación para reducir el tamaño en lugar de la velocidad. Esto significa no compilar funciones no utilizadas del motor, así como utilizar banderas específicas del compilador para ayudar a disminuir el tamaño de la compilación. Situaciones comunes incluyen crear compilaciones para plataformas móviles y Web.

Este tutorial tiene como objetivo proporcionar una visión general de diferentes métodos para crear un archivo binario más pequeño. Antes de continuar, se recomienda leer los tutoriales anteriores sobre cómo compilar Godot para cada plataforma.

Las opciones a continuación se enumeran desde la más importante (mayor ahorro de tamaño) hasta la menos importante (menor ahorro de tamaño).

Eliminación de símbolos de binarios

  • Ahorro de espacio: Muy alto

  • Dificultad: Fácil

  • Realizado en compilaciones oficiales:

Si compilas binarios para Windows (MinGW), Linux o macOS desde el código fuente, recuerda eliminar los símbolos de depuración de los binarios instalando el paquete strip desde tu distribución y luego ejecutando:

strip path/to/godot.binary

En Windows, strip.exe está incluido en la mayoría de las configuraciones del conjunto de herramientas MinGW.

Esto reducirá el tamaño de los binarios compilados en un factor entre 5× y 10×. La desventaja es que las trazas de fallos ya no proporcionarán información precisa (lo que es útil para solucionar problemas de un fallo). Los profilers de C++ tampoco podrán mostrar los nombres de las funciones (esto no afecta al profiler integrado de GDScript).

Nota

The above command will not work on Windows binaries compiled with MSVC and platforms such as Android and Web. Instead, pass debug_symbols=no on the SCons command line when compiling.

Optimizando para tamaño en lugar de velocidad

  • Ahorro de espacio: Alto

  • Dificultad: Fácil

  • Performed in official builds: Yes, but only for web builds

A partir de Godot 3.1 en adelante, es posible compilar utilizando optimizaciones de tamaño (en lugar de velocidad). Para habilitar esto, establece la bandera optimize en size:

scons target=template_release optimize=size

Algunas plataformas, como WebAssembly, ya utilizan este modo de forma predeterminada.

Disabling advanced text server

  • Ahorro de espacio: Alto

  • Dificultad: Fácil

  • Realizado en compilaciones oficiales: No

By default, Godot uses an advanced text server with the support for the following features:

  • Right-to-left typesetting and complex scripts, required to write languages such as Arabic and Hebrew.

  • Font ligatures and OpenType features (such as small capitals, fractions and slashed zero).

Godot provides a fallback text server that isn't compiled by default. This text server can be used as a lightweight alternative to the default advanced text server:

scons target=template_release module_text_server_adv_enabled=no module_text_server_fb_enabled=yes

If you only intend on supporting Latin, Greek and Cyrillic-based languages in your project, the fallback text server should suffice.

This fallback text server can also process large amounts of text more quickly than the advanced text server. This makes the fallback text server a good fit for mobile/web projects.

Nota

Remember to always pass module_text_server_fb_enabled=yes when using module_text_server_adv_enabled=no. Otherwise, the compiled binary won't contain any text server, which means no text will be displayed at all when running the project.

Desabilitando 3D

  • Ahorro de espacio: Moderado

  • Dificultad: Fácil

  • Realizado en compilaciones oficiales: No

Para juegos 2D, tener todo el motor 3D disponible generalmente no tiene sentido. Por esta razón, existe una opción de compilación para desactivarlo:

scons target=template_release disable_3d=yes

Las herramientas deben estar deshabilitadas para usar esta opción, ya que el editor no está diseñado para funcionar sin soporte 3D. Sin él, el tamaño del binario puede reducirse aproximadamente en un 15%.

Deshabilitar objetos de la GUI avanzados

  • Ahorro de espacio: Moderado

  • Dificultad: Fácil

  • Realizado en compilaciones oficiales: No

La mayoría de los juegos pequeños no requieren controles de GUI complejos como Tree, ItemList, TextEdit o GraphEdit. Pueden deshabilitarse usando una opción de compilación:

scons target=template_release disable_advanced_gui=yes

Esto es todo lo que será deshabilitado:

  • FileDialog

  • PopupMenu

  • Árbol

  • TextEdit

  • CodeEdit

  • SyntaxHighlighter

  • CodeHighlighter

  • TreeItem

  • OptionButton

  • SpinBox

  • ColorPicker

  • ColorPickerButton

  • RichTextlabel

  • RichTextEffect

  • CharFXTransform

  • AcceptDialog

  • ConfirmationDialog

  • MarginContainer

  • SubViewportContainer

  • SplitContainer

  • HSplitContainer

  • VSplitContainer

  • GraphNode

  • GraphEdit

Desactivando módulos no deseados

  • Ahorro de espacio: Muy bajo a moderado según los módulos

  • Dificultad: Media a alta según los módulos

  • Realizado en compilaciones oficiales: No

Muchas de las funciones de Godot se ofrecen como módulos. Puedes ver una lista de los módulos con el siguiente comando:

scons --help

La lista de módulos que pueden ser desactivados aparecerá junto con todas las opciones de compilación. Si estás trabajando en un juego simple en 2D, podrías desactivar muchos de ellos:

scons target=template_release module_basis_universal_enabled=no module_bmp_enabled=no module_camera_enabled=no module_csg_enabled=no module_dds_enabled=no module_enet_enabled=no module_gridmap_enabled=no module_hdr_enabled=no module_jsonrpc_enabled=no module_ktx_enabled=no module_mbedtls_enabled=no module_meshoptimizer_enabled=no module_minimp3_enabled=no module_mobile_vr_enabled=no module_msdfgen_enabled=no module_multiplayer_enabled=no module_noise_enabled=no module_navigation_enabled=no module_ogg_enabled=no module_openxr_enabled=no module_raycast_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_webrtc_enabled=no module_websocket_enabled=no module_webxr_enabled=no module_zip_enabled=no

If this proves not to work for your use case, you should review the list of modules and see which ones you actually still need for your game (e.g. you might want to keep networking-related modules, regex support, minimp3/ogg/vorbis to play music, or theora to play videos).

Como alternativa, puedes proporcionar una lista de módulos desactivados creando un archivo llamado custom.py en la raíz del código fuente, con un contenido similar al siguiente:

# custom.py

module_basis_universal_enabled = "no"
module_bmp_enabled = "no"
module_camera_enabled = "no"
module_csg_enabled = "no"
module_dds_enabled = "no"
module_enet_enabled = "no"
module_gridmap_enabled = "no"
module_hdr_enabled = "no"
module_jsonrpc_enabled = "no"
module_ktx_enabled = "no"
module_mbedtls_enabled = "no"
module_meshoptimizer_enabled = "no"
module_minimp3_enabled = "no"
module_mobile_vr_enabled = "no"
module_msdfgen_enabled= "no"
module_multiplayer_enabled = "no"
module_noise_enabled = "no"
module_navigation_enabled = "no"
module_ogg_enabled = "no"
module_openxr_enabled = "no"
module_raycast_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_webrtc_enabled = "no"
module_websocket_enabled = "no"
module_webxr_enabled = "no"
module_zip_enabled = "no"

Optimizing the distribution of your project

Desktop

Nota

This section is only relevant when distributing the files on a desktop platform that doesn't perform its own compression or packing. As such, this advice is relevant when you distribute ZIP archives on itch.io or GitHub Releases.

Platforms like Steam already apply their own compression scheme, so you don't need to create a ZIP archive to distribute files in the first place.

As an aside, you can look into optimizing the distribution of your project itself. This can be done even without recompiling the export template.

7-Zip can be used to create ZIP archives that are more efficient than usual, while remaining compatible with every ZIP extractor (including Windows' own built-in extractor). ZIP size reduction in a large project can reach dozens of megabytes compared to a typical ZIP compressor, although average savings are in the 1-5 MB range. Creating this ZIP archive will take longer than usual, but it will extract just as fast as any other ZIP archive.

When using the 7-Zip GUI, this is done by creating a ZIP archive with the Ultra compression mode. When using the command line, this is done using the following command:

7z a -mx9 my_project.zip folder_containing_executable_and_pck

Web

Enabling gzip or Brotli compression for all file types from the web export (especially the .wasm and .pck) can reduce the download size significantly, leading to faster loading times, especially on slow connections.

Creating precompressed gzip or Brotli files with a high compression level can be even more efficient, as long as the web server is configured to serve those files when they exist. When supported, Brotli should be preferred over gzip as it has a greater potential for file size reduction.

See Entrega de archivos for instructions.