Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


WasmCodeOptimization

Options for the optimization mode to use for compiling Web code.
Read time 1 minuteLast updated 6 days ago

Definition

public enum WasmCodeOptimization

Remarks

This enum provides optimization settings for WebAssembly (Wasm) code in Unity Web builds, enabling developers to balance file size, runtime performance, and build speed depending on their needs.

Examples

using UnityEditor;class WebOptimizer{ [MenuItem("Example/Optimize For Disk Size")] static void OptimizeForDiskSize() {#if UNITY_WEBGL // Set code optimization setting to optimize for disk size UnityEditor.WebGL.UserBuildSettings.codeOptimization = UnityEditor.WebGL.WasmCodeOptimization.DiskSize; // You will find the setting applied now in File > Build Settings > Web > Web Settings#endif}}

Fields

Value

Description

BuildTimesGenerate Web code that takes the least amount of time to build.
DiskSizeFavor optimizations that minimize build size, at the expense of taking a longer time to build compared to WasmCodeOptimization.BuildTimes.
DiskSizeLTOFavor optimizations that minimize build size, at the expense of taking a longer time to build compared to WasmCodeOptimization.BuildTimes. Also enable an additional Link Time Optimizations (LTO) stage.
DiskSizeMaxApply the maximum optimizations in favor of build size compared to WasmCodeOptimization.DiskSize.
DiskSizeMaxLTOApply the maximum optimizations in favor of build size compared to WasmCodeOptimization.DiskSizeLTO.
RuntimeSpeedGenerate Web code that’s optimized for runtime performance, at the expense of taking a longer time to build compared to WasmCodeOptimization.BuildTimes.
RuntimeSpeedLTOGenerate Web code that’s optimized for runtime performance, at the expense of taking a longer time to build compared to WasmCodeOptimization.BuildTimes. Also enable an additional Link Time Optimizations (LTO) stage.