# @debug has massive performance impact on Windows

**URL:** <https://discourse.julialang.org/t/debug-has-massive-performance-impact-on-windows/103974>\
**Category:** Performance\
**Created:** [September 18, 2023, 9:53am UTC](https://discourse.julialang.org/t/debug-has-massive-performance-impact-on-windows/103974 "2023-09-18T09:53:57Z")\
**Posts on this page:** 1\
**Showing post:** 22

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 18, 2023, 2:07pm UTC](https://discourse.julialang.org/t/debug-has-massive-performance-impact-on-windows/103974/22 "2023-09-18T14:07:20Z")

</div>

One could do something ugly and special case this in the environment lookup on Windows to prevent allocation for this specific case with the argument that the overhead of the string compare is negligible to the allocation from `cwstring`. But I am not sure that is acceptable.

```diff
diff --git a/base/env.jl b/base/env.jl
index 077b3a4ed2..c3c60da9c0 100644
--- a/base/env.jl
+++ b/base/env.jl
@@ -7,8 +7,10 @@ if Sys.iswindows()
     _hasenv(s::Vector{UInt16}) = _getenvlen(s) != 0 || Libc.GetLastError() != ERROR_ENVVAR_NOT_FOUND
     _hasenv(s::AbstractString) = _hasenv(cwstring(s))
 
+ const JULIA_DEBUG_CWSTRING = cwstring("JULIA_DEBUG")
+
     function access_env(onError::Function, str::AbstractString)
- var = cwstring(str)
+ var = str == "JULIA_DEBUG" ? JULIA_DEBUG_CWSTRING : cwstring(str)
         len = _getenvlen(var)
         if len == 0
             return Libc.GetLastError() != ERROR_ENVVAR_NOT_FOUND ? "" : onError(str)

```

---

_[View the full topic](https://discourse.julialang.org/t/debug-has-massive-performance-impact-on-windows/103974)._
