Dead Code Elimination (DCE) behavior during Haxe 4 production optimization
27.5K reputation · 25 Nov 2021, 15:16 UTC
In Haxe 4, the Dead Code Elimination (DCE) pass is designed to remove unused code to reduce the final binary or script size. While local debug builds typically preserve most code paths for easier inspection, production builds utilize higher optimization levels that aggressively prune the AST.
A challenge arises when code is accessed via dynamic reflection or specific target-specific macros that the compiler may not statically track. This creates a discrepancy where features function correctly in a development environment but are stripped out during the production compilation phase.
- How can the compiler be instructed to preserve specific classes or methods from DCE without disabling optimization for the entire project?
- What is the recommended mechanism to mark dynamically accessed code as "used" to ensure consistency between local and production builds?