# When does @inbounds increase performance?

**URL:** <https://discourse.julialang.org/t/when-does-inbounds-increase-performance/123827>\
**Category:** Performance\
**Tags:** inbounds\
**Created:** [December 14, 2024, 12:16am UTC](https://discourse.julialang.org/t/when-does-inbounds-increase-performance/123827 "2024-12-14T00:16:10Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [December 14, 2024, 4:31pm UTC](https://discourse.julialang.org/t/when-does-inbounds-increase-performance/123827/7 "2024-12-14T16:31:15Z")

</div>

E.g. a case where this optimization doesn’t happen is

> [@Is the triple \`@inbounds @fastmath @simd\` necessary for absolute peak performance?](https://discourse.julialang.org/t/is-the-triple-inbounds-fastmath-simd-necessary-for-absolute-peak-performance/121499/8):
>
> This is not always the case, unfortunately. Only in simple cases can the compiler elide bounds-checks with eachindex. E.g.: julia\> using LinearAlgebra julia\> function f(D) s = zero(eltype(D)) for i in eachindex(D) s += D[i] end s end f (generic function with 1 method) julia\> D = Diagonal(1:3); julia\> @code\_llvm f(D) this indicates that the bounds checks are still present. L28: ; preds = %L65, %top …

---

_[View the full topic](https://discourse.julialang.org/t/when-does-inbounds-increase-performance/123827)._
