Will Julia compile away lines like
ENV["JULIA_DEBUG"] == "MyModule" && expensive_debug_method()
when the environment variable is not set, or does the dictionary lookup happen at runtime? If the latter, is there a good way to implement nontrivial debug logic that will only be compiled in if ENV["JULIA_DEBUG"] == "MyModule"
? Or is my question poorly posed?
The use case is as follows. Our code implements a custom constrained optimization solver for a particular problem. We already have a bunch of @debug
messages that print convergence information at each iteration, and I see in the Logging section of the documentation that this has minimal performance impact because “the associated string processing will never be executed unless debug logging is enabled.”
Now, I want to add a debug-mode-only method that does some more expensive verification of the solver convergence (compute dual variables and checks KKT conditions). But if I write ENV["JULIA_DEBUG"] == "MyModule" && check_kkt()
, then I want Julia to forgo compiling the check_kkt()
method unless and until someone enables debug mode (i.e. never in production).
Is this something I should care about, and if so, is the implementation correct?