Skip to main content

Module env_flags

Module env_flags 

Source
Expand description

Cached reads of the CRANPOSE_* diagnostic environment variables.

Every diagnostic switch in the framework is read from the environment, and several of them sit on paths that run once per frame, once per state write, or once per laid-out node. That is a problem, because reading an environment variable is not a cheap lookup: getenv takes the environ lock and walks the whole variable array, comparing each entry’s name prefix, until it finds a match or runs off the end. A switch that is turned off is the worst case — it never matches, so every read pays for a full scan of the process environment just to learn there is nothing to print. On a device that showed up as a measurable share of an idle frame, spent entirely inside strncmp.

None of these switches can change after startup. Android’s are seeded from debug.cranpose.* system properties before the app shell exists, and on every other platform they come from the process environment, which the framework never mutates. So each one is read once and cached.

Use [env_flag!] for presence switches and [env_threshold_ms!] for the millisecond thresholds. Both expand to a OnceLock owned by the call site, which costs an acquire load once warm.