# Startup option to turn off @assert

**URL:** https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238
**Category:** General Usage
**Tags:** performance
**Created:** [April 20, 2025, 7:42am UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238 "2025-04-20T07:42:32Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [April 20, 2025, 7:42am UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/1 "2025-04-20T07:42:32Z")

</div>

I often use something like

```julia
@boundscheck all(x .> 0) || error()

```

instead of

```julia
@assert all(x .> 0)

```

so that I could “test run” the code first. If no error, I would then start with `check-bounds=no` to run the code in “performance mode”.

I know, I know, it’s not the intended designed use of `@boundscheck` but it works fine before v1.10. Basically it appears in every function I wrote.

Given the current performance regression of `check-bounds=no` since v1.10, I would ask for a startup option like `to-assert=no` such that I would turn off all `@assert` for performance.

---

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [April 20, 2025, 1:47pm UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/2 "2025-04-20T13:47:21Z")

</div>

anyone has the same problem as mine?

---

<div class="post-metadata">

### Author: ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)
#### Post date: [April 20, 2025, 2:32pm UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/3 "2025-04-20T14:32:22Z")

</div>

I think there is no official way, yet. However, you can run your own with slight inconveniences.

You can use [`@static`](https://docs.julialang.org/en/v1/base/base/#Base.@static) or something similar to depend on a state (a command line argument, an environment variable or something else) to conditionally define a macro to do something or not (like the checks you do with `@boundscheck`). Obviously, this means that the module needs to be recompiled when this state changes, but that’s the price to pay for maximum performance when the mechanism is deactivated. This is similar to what `@debug` does.

The inconvenience is, that the behavior now depends on this state at the time of compilation. If this state changes, Julia’s regular mechanisms won’t notice and therefore the needed recompilation won’t happen on its own. There are probably all sorts of ways how to trigger the recompilation, the most trivial might be to simply add a semicolon at the end of one of your `.jl` files in the module. This will change the hash and therefore trigger recompilation.

If you want you can additionally add a runtime check of this state when compiled with “test/debug mode”. This way you can quickly switch between the modes (without getting full performance, probably only worth if the tests are a bit heavier) and can still switch to full performance (but again only with recompilation).

---

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [April 20, 2025, 2:34pm UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/4 "2025-04-20T14:34:40Z")

</div>

could u illustrate the use of @static with command line argument?

I use check-bounds because it’s the only command line argument I could set AFAIK

---

<div class="post-metadata">

### Author: ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)
#### Post date: [April 20, 2025, 2:42pm UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/5 "2025-04-20T14:42:05Z")

</div>

there’s some discussion here [Do something about `@assert` · Issue #51729 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/51729)

---

<div class="post-metadata">

### Author: ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)
#### Post date: [April 20, 2025, 2:45pm UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/6 "2025-04-20T14:45:54Z")

</div>

You can hand over [arbitrary command line options after `--`](https://docs.julialang.org/en/v1/manual/command-line-interface/#Using-arguments-inside-scripts):

```julia
> julia -e 'println(@static isempty(Base.ARGS) ? "performance" : "test")'
performance

> julia -e 'println(@static isempty(Base.ARGS) ? "performance" : "test")' -- --my-custom-option
test

```

Obviously, you would use a more robust check than this and do something else in your code than providing the code directly and only doing conditional printing.

---

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [April 20, 2025, 2:54pm UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/7 "2025-04-20T14:54:11Z")

</div>

I don’t understand @static …

in your example. What’s the difference without using @static ?

---

<div class="post-metadata">

### Author: ![PatrickHaecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/patrickhaecker/32/222891_2.png) [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)
#### Post date: [April 21, 2025, 5:53am UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/8 "2025-04-21T05:53:04Z")

</div>

When providing the code to execute as in my example, there is no practical difference. However, when you have that code in a `.jl` file within a package, you’ll notice the difference.

Without `@static` it will do a runtime check. In your use case, `all(x .> 0)` will not be checked, but a test whether this needs to be calculated is still evaluated.

With `@static` the test whether to calculate `all(x .> 0)` is removed, too, during precompilation of your module.

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [April 21, 2025, 7:44am UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/9 "2025-04-21T07:44:28Z")

</div>

> [@tomtom](#):
>
> I would then start with `check-bounds=no` to run the code in “performance mode”.

Probably a bad idea. The `--check-bounds=no` setting actually often makes performance worse, because it inhibits the Julia compiler’s inference and optimization.

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [April 21, 2025, 7:45am UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/10 "2025-04-21T07:45:46Z")

</div>

> [@tomtom](#):
>
> What’s the difference without using @static ?

`@static` does the branch at macro expansion time, which is during load time.

---

<div class="post-metadata">

### Author: ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)
#### Post date: [April 21, 2025, 7:56am UTC](https://discourse.julialang.org/t/startup-option-to-turn-off-assert/128238/11 "2025-04-21T07:56:38Z")

</div>

performance regression in bounds-check=no is definitely not a desirable outcome and it led to a lot of discussions recently.
