Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify and slightly improve memorynew inference #56857

Merged
merged 4 commits into from
Dec 23, 2024

Conversation

oscardssmith
Copy link
Member

@oscardssmith oscardssmith commented Dec 17, 2024

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).

@oscardssmith oscardssmith added performance Must go faster arrays [a, r, r, a, y, s] labels Dec 17, 2024
@oscardssmith
Copy link
Member Author

this appears to be ready to merge. will do so in a few days sans objections

@oscardssmith oscardssmith merged commit 8fac39b into JuliaLang:master Dec 23, 2024
7 checks passed
@oscardssmith oscardssmith deleted the os/simplify-copy-array branch December 23, 2024 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant