# Making views the default indexing behavior in 2.0?

**URL:** <https://discourse.julialang.org/t/making-views-the-default-indexing-behavior-in-2-0/29954>\
**Category:** Internals & Design\
**Tags:** speculative\
**Created:** [October 12, 2019, 11:10pm UTC](https://discourse.julialang.org/t/making-views-the-default-indexing-behavior-in-2-0/29954 "2019-10-12T23:10:08Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [October 13, 2019, 8:30am UTC](https://discourse.julialang.org/t/making-views-the-default-indexing-behavior-in-2-0/29954/5 "2019-10-13T08:30:26Z")

</div>

> [@Avoiding a Julia version of the Python 2/3 mess](https://discourse.julialang.org/t/avoiding-a-julia-version-of-the-python-2-3-mess/29759/12):
>
> direction for lookup or suboptimal memory access, so this could make some code (a lot) slower. Cf

Optimized BLAS libraries pack, copying elements into preallocated blocks for better locality.  
[Here](https://discourse.julialang.org/t/we-can-write-an-optimized-blas-library-in-pure-julia-please-skip-op-and-jump-to-post-4/11634/16) is a comment explaining how important it is to performance, by mratsim who implemented a high performance BLAS in Nim.

In Fortran, the gfortran compiler uses views when they are contiguous, but copies otherwise. This is often a good heuristic, but can prevent vectorization if not inlined when using a struct-of-arrays style memory layout (where what would be the fields to the struct are distributed across the columns of a matrix). If inlined, the compiler will hopefully make the correct perform- vs eliminate-the-copy decision.  
If the calling function mutates the view, gfortran also emits an unpack, to maintain the same behavior in both versions.

Perhaps a view is only ever up to several times slower than a copy, but couldn’t the same normally be said about a copy, barring fairly extreme cases, such as

```julia
foo(x) = x[1] + 1

function bar(x)
    s = zero(eltype(x))
    @inbounds @simd for i ∈ eachindex(x)
        #s += @views foo(x[i:i])
        s += foo(x[i:i])
    end
    s
end

```

---

_[View the full topic](https://discourse.julialang.org/t/making-views-the-default-indexing-behavior-in-2-0/29954)._
