Skip to content

Commit

Permalink
Allow compiling editor with target=release for aggressive optimization
Browse files Browse the repository at this point in the history
This keeps the required debug functionality enabled, but `-O3` is
used instead of `-O2`.

The resulting binary is a few megabytes larger, but there are
non-negligible run-time performance gains, including editor startup
and shutdown speeds.
  • Loading branch information
Calinou committed Jul 5, 2022
1 parent 63752df commit 0faac33
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
tests: false # Disabled due freeze caused by mix Mono build and CI
sconsflags: module_mono_enabled=yes mono_static=yes mono_glue=no
doc-test: true
bin: "./bin/godot.linuxbsd.opt.tools.64.mono"
bin: "./bin/godot.linuxbsd.opt.debug.tools.64.mono"
build-mono: true
proj-conv: true
artifact: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
target: release_debug
tools: true
tests: true
bin: "./bin/godot.osx.opt.tools.64"
bin: "./bin/godot.osx.opt.debug.tools.64"

- name: Template (target=release, tools=no)
cache-name: macos-template
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
tests: true
# Skip debug symbols, they're way too big with MSVC.
sconsflags: debug_symbols=no
bin: "./bin/godot.windows.opt.tools.64.exe"
bin: "./bin/godot.windows.opt.debug.tools.64.exe"

- name: Template (target=release, tools=no)
cache-name: windows-template
Expand Down
20 changes: 13 additions & 7 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,11 @@ env_base.platform_exporters = platform_exporters
env_base.platform_apis = platform_apis

# Build type defines - more platform-specific ones can be in detect.py.
if env_base["target"] == "release_debug" or env_base["target"] == "debug":
if (
(env_base["tools"] and env_base["target"] == "release")
or env_base["target"] == "release_debug"
or env_base["target"] == "debug"
):
# DEBUG_ENABLED enables debugging *features* and debug-only code, which is intended
# to give *users* extra debugging information for their game development.
env_base.Append(CPPDEFINES=["DEBUG_ENABLED"])
Expand Down Expand Up @@ -632,14 +636,16 @@ if selected_platform in platform_list:

if env["target"] == "release":
if env["tools"]:
print("ERROR: The editor can only be built with `target=debug` or `target=release_debug`.")
print(" Use `tools=no target=release` to build a release export template.")
Exit(255)
suffix += ".opt"
env.Append(CPPDEFINES=["NDEBUG"])
suffix += ".opt.tools"
else:
suffix += ".opt"
# Debugging functionality is required for editor builds.
# `target=release` will still use more aggressive optimization compared to `target=release_debug`,
# but the optimization won't be as aggressive as in non-editor builds.
env.Append(CPPDEFINES=["NDEBUG"])
elif env["target"] == "release_debug":
if env["tools"]:
suffix += ".opt.tools"
suffix += ".opt.debug.tools"
else:
suffix += ".opt.debug"
else:
Expand Down
2 changes: 1 addition & 1 deletion methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ class ModuleConfigs(Mapping):
PLATFORMS = ["Win32", "x64"]
PLATFORM_IDS = ["32", "64"]
CONFIGURATIONS = ["debug", "release", "release_debug"]
CONFIGURATION_IDS = ["tools", "opt", "opt.tools"]
CONFIGURATION_IDS = ["tools", "opt", "opt.debug.tools"]

@staticmethod
def for_every_variant(value):
Expand Down
23 changes: 10 additions & 13 deletions platform/android/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,6 @@ def templateExcludedBuildTask() {
logger.lifecycle("Excluding Android studio build tasks")
for (String flavor : supportedFlavors) {
for (String buildType : supportedTargetsMap.keySet()) {
if (buildType == "release" && flavor == "editor") {
// The editor can't be used with target=release as debugging tools are then not
// included, and it would crash on errors instead of reporting them.
continue
}

for (String abi : selectedAbis) {
excludedTasks += ":lib:" + getSconsTaskName(flavor, buildType, abi)
}
Expand Down Expand Up @@ -214,11 +208,18 @@ def isAndroidStudio() {
return sysProps != null && sysProps['idea.platform.prefix'] != null
}

task copyEditorReleaseBinaryToBin(type: Copy) {
dependsOn ':editor:assembleRelease'
from('editor/build/outputs/apk/release')
into(binDir)
include('android_editor_release.apk')
}

task copyEditorDebugBinaryToBin(type: Copy) {
dependsOn ':editor:assembleDebug'
from('editor/build/outputs/apk/debug')
into(binDir)
include('android_editor.apk')
include('android_editor_debug.apk')
}

task copyEditorDevBinaryToBin(type: Copy) {
Expand All @@ -241,11 +242,6 @@ task generateGodotEditor {
def tasks = []

for (String target : supportedTargetsMap.keySet()) {
if (target == "release") {
// The editor can't be used with target=release as debugging tools are then not
// included, and it would crash on errors instead of reporting them.
continue
}
File targetLibs = new File("lib/libs/tools/" + target)
if (targetLibs != null
&& targetLibs.isDirectory()
Expand Down Expand Up @@ -295,7 +291,8 @@ task cleanGodotEditor(type: Delete) {
delete("editor/build/outputs/apk")

// Delete the Godot editor apks in the Godot bin directory
delete("$binDir/android_editor.apk")
delete("$binDir/android_editor_release.apk")
delete("$binDir/android_editor_debug.apk")
delete("$binDir/android_editor_dev.apk")

finalizedBy getTasksByName("clean", true)
Expand Down
18 changes: 3 additions & 15 deletions platform/android/java/editor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@ android {
}

debug {
initWith release

// Need to swap with the release signing config when this is ready for public release.
signingConfig signingConfigs.debug
applicationIdSuffix ".debug"
}

release {
// This buildtype is disabled below.
// The editor can't be used with target=release only, as debugging tools are then not
// included, and it would crash on errors instead of reporting them.
initWith release
}
}

Expand All @@ -64,18 +61,9 @@ android {
}
}

// Disable 'release' buildtype.
// The editor can't be used with target=release only, as debugging tools are then not
// included, and it would crash on errors instead of reporting them.
variantFilter { variant ->
if (variant.buildType.name == "release") {
setIgnore(true)
}
}

applicationVariants.all { variant ->
variant.outputs.all { output ->
def suffix = variant.name == "dev" ? "_dev" : ""
def suffix = "_" + variant.name
output.outputFileName = "android_editor${suffix}.apk"
}
}
Expand Down
10 changes: 1 addition & 9 deletions platform/android/java/lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,7 @@ android {
// Editor jni library
editorDebug.jniLibs.srcDirs = ['libs/tools/debug']
editorDev.jniLibs.srcDirs = ['libs/tools/dev']
}

// Disable 'editorRelease'.
// The editor can't be used with target=release as debugging tools are then not
// included, and it would crash on errors instead of reporting them.
variantFilter { variant ->
if (variant.name == "editorRelease") {
setIgnore(true)
}
editorRelease.jniLibs.srcDirs = ['libs/tools/release']
}

libraryVariants.all { variant ->
Expand Down
1 change: 1 addition & 0 deletions platform/linuxbsd/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def configure(env):

elif env["target"] == "release_debug":
if env["optimize"] == "speed": # optimize for speed (default)
# `-O2` is more friendly to debuggers than `-O3`, leading to better crash backtraces.
env.Prepend(CCFLAGS=["-O2"])
elif env["optimize"] == "size": # optimize for size
env.Prepend(CCFLAGS=["-Os"])
Expand Down
1 change: 1 addition & 0 deletions platform/osx/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def configure(env):

elif env["target"] == "release_debug":
if env["optimize"] == "speed": # optimize for speed (default)
# `-O2` is more friendly to debuggers than `-O3`, leading to better crash backtraces.
env.Prepend(CCFLAGS=["-O2"])
elif env["optimize"] == "size": # optimize for size
env.Prepend(CCFLAGS=["-Os"])
Expand Down
19 changes: 8 additions & 11 deletions platform/windows/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,23 @@ def configure_mingw(env):

if env["target"] == "release":
env.Append(CCFLAGS=["-msse2"])

if env["optimize"] == "speed": # optimize for speed (default)
if env["bits"] == "64":
env.Append(CCFLAGS=["-O3"])
else:
env.Append(CCFLAGS=["-O2"])
env.Append(CCFLAGS=["-O3"])
else: # optimize for size
env.Prepend(CCFLAGS=["-Os"])
env.Append(CCFLAGS=["-Os"])

if env["debug_symbols"]:
env.Prepend(CCFLAGS=["-g2"])
env.Append(CCFLAGS=["-g2"])

elif env["target"] == "release_debug":
env.Append(CCFLAGS=["-O2"])
if env["debug_symbols"]:
env.Prepend(CCFLAGS=["-g2"])
if env["optimize"] == "speed": # optimize for speed (default)
# `-O2` is more friendly to debuggers than `-O3`, leading to better crash backtraces.
env.Append(CCFLAGS=["-O2"])
else: # optimize for size
env.Prepend(CCFLAGS=["-Os"])
env.Append(CCFLAGS=["-Os"])

if env["debug_symbols"]:
env.Append(CCFLAGS=["-g2"])

elif env["target"] == "debug":
env.Append(CCFLAGS=["-g3"])
Expand Down

0 comments on commit 0faac33

Please sign in to comment.