# \#inbounds

**URL:** https://discourse.julialang.org/tag/inbounds/920.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [@inbounds slower](https://discourse.julialang.org/t/inbounds-slower/126634)

<div class="topic-metadata">

**Author:** [@eldee](https://discourse.julialang.org/u/eldee)\
**Replies:** 8\
**Last updated:** [March 25, 2025, 1:52am UTC](https://discourse.julialang.org/t/inbounds-slower/126634 "2025-03-25T01:52:00Z")

</div>

Hi, I’m encountering some situations in my GPU code where adding @inbounds increases execution time by 10%-20%. Of course it would be great if we would never need @inbounds, but on the other hand there are certainly als…

---

## [When does @inbounds increase performance?](https://discourse.julialang.org/t/when-does-inbounds-increase-performance/123827)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 14\
**Last updated:** [February 14, 2025, 1:00am UTC](https://discourse.julialang.org/t/when-does-inbounds-increase-performance/123827 "2025-02-14T01:00:44Z")

</div>

I am interested in making some optimizations in my software. I noticed many packages make use of the @inbounds macro, and the Julia manual mentions @inbounds in its performance tips section (Performance Tips · The Julia …

---

## [Removing bounds checking for HPC - \`--check-bounds=unsafe\`?](https://discourse.julialang.org/t/removing-bounds-checking-for-hpc-check-bounds-unsafe/124897)

<div class="topic-metadata">

**Author:** [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Replies:** 51\
**Last updated:** [February 1, 2025, 4:05pm UTC](https://discourse.julialang.org/t/removing-bounds-checking-for-hpc-check-bounds-unsafe/124897 "2025-02-01T16:05:26Z")

</div>

One of Julia’s main purposes is to enable high-performance computing at scale - it’s on the front page (Ecosystem → Parallel Computing at The Julia Programming Language)! However, apparently --check-bounds=no is becoming…

---

## [Why does \`@inbounds\` disable constant propagation?](https://discourse.julialang.org/t/why-does-inbounds-disable-constant-propagation/105789)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 25\
**Last updated:** [January 20, 2025, 12:00am UTC](https://discourse.julialang.org/t/why-does-inbounds-disable-constant-propagation/105789 "2025-01-20T00:00:58Z")

</div>

The Julia manual says: An explicit @inbounds annotation inside the function will also disable constant folding and not be overridden by :foldable. Some other references of this fact: Issue #48245 says: turning on -…

---

## [Bounds check performance](https://discourse.julialang.org/t/bounds-check-performance/121741)

<div class="topic-metadata">

**Author:** [@shatanzikou](https://discourse.julialang.org/u/shatanzikou)\
**Replies:** 2\
**Last updated:** [October 25, 2024, 4:11pm UTC](https://discourse.julialang.org/t/bounds-check-performance/121741 "2024-10-25T16:11:40Z")

</div>

The SciML Style guide reads that in Julia after ver1.9, bounds check will reduce performance. But I didn’t see others recommended this, there is no performance reducing in my test. I want to know why it is not recommende…

---

## [@inbounds for getindex not working](https://discourse.julialang.org/t/inbounds-for-getindex-not-working/118631)

<div class="topic-metadata">

**Author:** [@Andy\_Zhang](https://discourse.julialang.org/u/Andy_Zhang)\
**Replies:** 2\
**Last updated:** [August 26, 2024, 4:24pm UTC](https://discourse.julialang.org/t/inbounds-for-getindex-not-working/118631 "2024-08-26T16:24:32Z")

</div>

Here is the example code and output. struct Minij{T\<:Number} \<: AbstractMatrix{T} n::Integer function Minij{T}(n::Integer) where {T\<:Number} n \>= 0 || throw(ArgumentError("$n \< 0")) return new{T…

---

## [Why is the bounds-checking not elided in isassigned for \`SlowSubArray\`s despite an inbounds annotation?](https://discourse.julialang.org/t/why-is-the-bounds-checking-not-elided-in-isassigned-for-slowsubarray-s-despite-an-inbounds-annotation/110019)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 0\
**Last updated:** [February 10, 2024, 7:12am UTC](https://discourse.julialang.org/t/why-is-the-bounds-checking-not-elided-in-isassigned-for-slowsubarray-s-despite-an-inbounds-annotation/110019 "2024-02-10T07:12:03Z")

</div>

Function definition julia\> function mycopyto!(dest::AbstractArray, src::AbstractArray) iterdest, itersrc = eachindex(dest), eachindex(src) @inbounds for I in iterdest if isassigned(s…

---

## [Remove bounds checking for the entire program](https://discourse.julialang.org/t/remove-bounds-checking-for-the-entire-program/109339)

<div class="topic-metadata">

**Author:** [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Replies:** 8\
**Last updated:** [January 27, 2024, 6:38pm UTC](https://discourse.julialang.org/t/remove-bounds-checking-for-the-entire-program/109339 "2024-01-27T18:38:53Z")

</div>

I don’t need bound checking. Instead of writing @inbounds everywhere, can I test my program without it and then, when it all works, enable a flag which disables all the bound checking and other automatic behaviours typi…

---

## [What does @inbounds actually mean?](https://discourse.julialang.org/t/what-does-inbounds-actually-mean/102592)

<div class="topic-metadata">

**Author:** [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Replies:** 8\
**Last updated:** [August 8, 2023, 12:40pm UTC](https://discourse.julialang.org/t/what-does-inbounds-actually-mean/102592 "2023-08-08T12:40:16Z")

</div>

In the discussion on https://github.com/JuliaLang/julia/issues/48245 it was mentioned that Just to be clear, the reason we want to remove it is it requires us to compile the code more conservatively, leading to signifi…

---

## [Keyword arguments preventing eliding boundscheck](https://discourse.julialang.org/t/keyword-arguments-preventing-eliding-boundscheck/95405)

<div class="topic-metadata">

**Author:** [@OmarElrefaei](https://discourse.julialang.org/u/OmarElrefaei)\
**Replies:** 2\
**Last updated:** [March 1, 2023, 8:59pm UTC](https://discourse.julialang.org/t/keyword-arguments-preventing-eliding-boundscheck/95405 "2023-03-01T20:59:42Z")

</div>

So I’ve got a MWE here with a weird behavior. Note: this seems to be actually fixed in v1.9. But I couldn’t track any relevant issues to PR. I’m trying to elide some checking code with @boundscheck. (yes, the real use …

---

## [What is the most idiomatic way to implement bounds checking in \`getindex\` for arbitrary types?](https://discourse.julialang.org/t/what-is-the-most-idiomatic-way-to-implement-bounds-checking-in-getindex-for-arbitrary-types/94779)

<div class="topic-metadata">

**Author:** [@loonatick-src](https://discourse.julialang.org/u/loonatick-src)\
**Replies:** 3\
**Last updated:** [February 18, 2023, 4:34am UTC](https://discourse.julialang.org/t/what-is-the-most-idiomatic-way-to-implement-bounds-checking-in-getindex-for-arbitrary-types/94779 "2023-02-18T04:34:47Z")

</div>

Specifically, I have two main requirements in mind. It should throw BoundsError with complete information. The @inbounds macro should work as intended for this type, i.e. elide the bounds checking entirely Item 1 seem…

---

## [Disabling DomainError (in sqrt())?](https://discourse.julialang.org/t/disabling-domainerror-in-sqrt/88755)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 21\
**Last updated:** [October 17, 2022, 9:20pm UTC](https://discourse.julialang.org/t/disabling-domainerror-in-sqrt/88755 "2022-10-17T21:20:30Z")

</div>

Is there any way one can remove the negative number check for sqrt(Float64)? Neither @inbounds or @fastmath seems to do the trick (by checking the generated @code\_native). However, it seems that, say, LinearAlgebra.norm(…

---

## [Question on Julia Blog Post regarding Performance](https://discourse.julialang.org/t/question-on-julia-blog-post-regarding-performance/87342)

<div class="topic-metadata">

**Author:** [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Replies:** 1\
**Last updated:** [September 16, 2022, 3:48am UTC](https://discourse.julialang.org/t/question-on-julia-blog-post-regarding-performance/87342 "2022-09-16T03:48:15Z")

</div>

I was searching around for Julia comparisons to C++ and found this write-up from 2019. I follow most of it but one point I was curious about is near the end where they implemented @simd, @fastmath, and @inbounds. I wou…

---

## [Segfault that I cannot explain, possibly related to Zygote](https://discourse.julialang.org/t/segfault-that-i-cannot-explain-possibly-related-to-zygote/74509)

<div class="topic-metadata">

**Author:** [@cortner](https://discourse.julialang.org/u/cortner)\
**Replies:** 0\
**Last updated:** [January 12, 2022, 8:20pm UTC](https://discourse.julialang.org/t/segfault-that-i-cannot-explain-possibly-related-to-zygote/74509 "2022-01-12T20:20:18Z")

</div>

Naively maybe, I assumed that segfaults will only occur if I access memory I don’t own. Therefore, in Julia, with bounds checking turned on, it simply shouldn’t occur? I’ve now run into a case where the opposite happens…
