module
Lapis::Docs::B_LAPIS_CLI_AND_TOOLCHAIN::L_COMPILE_FLAGS_AND_OPTIMIZATION
Overview
Compile-Time Flags & Optimization
Comprehensive guide to compile-time configuration flags across Lapis, covering binary size optimization, thread-safety check elision, and opt-in diagnostic instrumentation for memory leaks, signals, and dispatches.
Executive Summary & Key Topics
| Topic | Method / Anchor | Description |
|---|---|---|
| Compile-Time Flag Matrix | .topic_00_optimization_flags |
Listing of binary stripping and diagnostic compiler switches. |
| Producing Ultra-Lean Production Binaries | .topic_01_stripping_lean_binaries |
Stripping docstrings, XML help registries, and test scaffolding. |
| High-Throughput Thread-Safety Bypass | .topic_02_thread_safety_bypass |
Eliminating main-thread assertions for maximum scene graph dispatch speed. |
| Opt-In Diagnostic Instrumentation | .topic_03_diagnostic_instrumentation |
Enabling memory leak tracking, method dispatch profiling, and dead-pointer callstacks. |
| CLI Switches & Environment Variables | .topic_04_cli_integration |
Invoking flags via lapis CLI options or environment variables. |
Related Guides & Source References
- Build Command:
tools/lapis/src/commands/build.cr - Diagnostics Implementation:
src/libgodot/diagnostics.cr - Specifications:
spec/compile_flags_spec.cr
Defined in:
libgodot/docs/b_lapis_cli_and_toolchain/l_compile_flags_and_optimization.crClass Method Summary
-
.topic_00_optimization_flags : Nil
Compile-Time Flag Matrix: Listing of binary stripping and diagnostic compiler switches.
-
.topic_01_stripping_lean_binaries : Nil
Producing Ultra-Lean Production Binaries: Stripping docstrings, XML help registries, and test scaffolding.
-
.topic_02_thread_safety_bypass : Nil
High-Throughput Thread-Safety Bypass: Eliminating main-thread assertions for maximum scene graph dispatch speed.
-
.topic_03_diagnostic_instrumentation : Nil
Opt-In Diagnostic Instrumentation: Enabling memory leak tracking, method dispatch profiling, and dead-pointer callstacks.
-
.topic_04_cli_integration : Nil
CLI Switches & Environment Variables: Invoking flags via lapis CLI options or environment variables.
Class Method Detail
Compile-Time Flag Matrix: Listing of binary stripping and diagnostic compiler switches.
Key Topics & Information
- --strip-docs (-Dno_doc): Strips doc comments and EditorHelp XML strings
- --no-thread-safety (-Dno_thread_safety): Bypasses main-thread runtime guards
- --no-testing (-Dno_testing): Excludes test suites from consumer deliverables
- --no-crash-handler (-Dno_crash_handler): Disables Windows VEH handler for clean radare2 execution
- --leak-tracker (-Dleak_tracker): Tracks object allocations, call sites, and surviving instances
- --profile-dispatches (-Dprofile_dispatches): Records nanosecond virtual method dispatch latency
- --trace-dead-pointers (-Dtrace_dead_pointers): Maintains deallocation callstacks for DisposedObjectError
- --trace-signals (-Dtrace_signals): Intercepts and logs scene tree signal emissions
Producing Ultra-Lean Production Binaries: Stripping docstrings, XML help registries, and test scaffolding.
During release compilation, binary size can be minimized by stripping metadata unnecessary for runtime gameplay:
# Strip docs, XML help, and test scaffolding
lapis build --release --strip-docs --no-testing
--strip-docs(-Dno_doc): Strips out hundreds of kilobytes of extracted doc comments and XML help structures fromsrc/libgodot/macros.crandsrc/libgodot/doc_macro.cr. Automatically enabled in--release.--no-testing(-Dno_testing): Omit test runners and benchmark harnesses from consumer games.
High-Throughput Thread-Safety Bypass: Eliminating main-thread assertions for maximum scene graph dispatch speed.
By default, LibGodot guards scene tree mutations (add_child, remove_child) with Godot::ThreadSafety.assert_main_thread!.
For battle-tested, single-threaded game loops, these checks can be completely elided at compile time:
lapis build --release --no-thread-safety
When compiled with --no-thread-safety (or -Dfast_dispatch), assert_main_thread! becomes a zero-cost compiler no-op, eliminating thread ID queries and branch predictions on hot loops.
Opt-In Diagnostic Instrumentation: Enabling memory leak tracking, method dispatch profiling, and dead-pointer callstacks.
When debugging complex engine interactions, Lapis provides low-overhead diagnostic modules:
Memory Leak Tracking:
lapis build --leak-tracker
Logs every object allocation with source file and line. At shutdown, inspect surviving objects:
Virtual Method Dispatch Latency Profiling:
lapis build --profile-dispatches
Captures invocation count, average nanoseconds, minimum, and maximum latency for all virtual calls into Crystal.
Dead-Pointer Destruction Callstack History:
lapis build --trace-dead-pointers
Maintains a ring buffer of deallocated instances so any subsequent DisposedObjectError pinpoints where the node was freed.
CLI Switches & Environment Variables: Invoking flags via lapis CLI options or environment variables.
All optimization and diagnostic flags can be specified through CLI switches or environment variables:
| Switch | Environment Variable | Crystal Flag |
|---|---|---|
--strip-docs |
STRIP_DOCS=1 |
-Dno_doc |
--no-thread-safety |
NO_THREAD_SAFETY=1 |
-Dno_thread_safety |
--leak-tracker |
LEAK_TRACKER=1 |
-Dleak_tracker |
--profile-dispatches |
PROFILE_DISPATCHES=1 |
-Dprofile_dispatches |
--trace-dead-pointers |
TRACE_DEAD_POINTERS=1 |
-Dtrace_dead_pointers |
--trace-signals |
TRACE_SIGNALS=1 |
-Dtrace_signals |
--no-crash-handler |
NO_CRASH_HANDLER=1 |
-Dno_crash_handler |