You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
simplify and slightly improve memorynew inference (#56857)
while investigating some missed optimizations in
#56847, @gbaraldi and I realized
that `copy(::Array)` was using `jl_genericmemory_copy_slice` rather than
the `memmove`/`jl_genericmemory_copyto` that `copyto!` lowers to. This
version lets us use the faster LLVM based Memory initialization, and the
memove can theoretically be further optimized by LLVM (e.g. not copying
elements that get over-written without ever being read).
```
julia> @Btime copy($[1,2,3])
15.521 ns (2 allocations: 80 bytes) # before
12.116 ns (2 allocations: 80 bytes) #after
julia> m = Memory{Int}(undef, 3);
julia> m.=[1,2,3];
julia> @Btime copy($m)
11.013 ns (1 allocation: 48 bytes) #before
9.042 ns (1 allocation: 48 bytes) #after
```
We also optimize the `memorynew` type inference to make it so that
getting the length of a memory with known length will propagate that
length information (which is important for cases like `similar`/`copy`
etc).
0 commit comments