Skip to content

Release Optimization

kirich1409 edited this page May 18, 2026 · 1 revision

Release Optimization

TL;DR: a flag declared with default = false makes every code path behind its generated accessor unreachable in release builds. R8 strips it on Android/JVM; the Swift compiler strips it on iOS via compilation conditions. No runtime cost, no leftover dead code.

Featured eliminates dead code from release builds. Flags declared with default = false make all code behind their generated accessors unreachable, and the Gradle plugin emits the rules that tell each compiler to act on that fact.

How it works

Android / JVM — R8

The Gradle plugin generates per-function ProGuard / R8 -assumevalues rules for every local boolean flag with default = false. These rules instruct R8 to treat the flag as a constant false at shrink time. R8 constant-folds the accessor call, determines the guarded branch is unreachable, and removes it from the output APK or JAR.

The task runs automatically as part of the release build. No configuration is required.

See Android — R8 DCE for the full story: rule format, task name, output path, and verification.

iOS — xcconfig

The Gradle plugin generates an xcconfig file containing SWIFT_ACTIVE_COMPILATION_CONDITIONS with a DISABLE_<FLAG_KEY> entry for every local boolean flag with default = false. When this file is included in the Xcode Release configuration, the Swift compiler sees the condition as defined and physically removes every block guarded by #if !DISABLE_<FLAG_KEY>.

See iOS — xcconfig DCE for the four-step setup, key transformation table, and the pre-build automation script.

What about remote flags?

Remote flag values are fetched at runtime — the compiler cannot know their values at build time. Remote flags are therefore never eligible for DCE. Only localFlags declarations with default = false generate shrink rules.

If you want a flag to eventually be removed, start it as a localFlag with default = false, roll it out remotely by overriding the local value, then clean up the flag declaration once the rollout is complete and the code is fully removed. See Best Practices for the full lifecycle.

Clone this wiki locally