In the Chinese community of Julia, someone opened a topic complaining that Julia's code took up too much memory.
After the performance test (julia --track-allocation=user filename.jl), I found that Base.circshift took up the most memory.
After some searching, I found this package, and by using this package, the memory consumption problem was solved.
using Base.circshift: "6.694 s (3507 allocations: 2.55 GiB)"
allocation count (estimate using --track-allocation flag):
2617296789 @views f[:, :, k] .= circshift(f[:, :, k], [cx[k], cy[k]])
Some real world case:
In the Chinese community of Julia, someone opened a topic complaining that Julia's code took up too much memory. After the performance test (
julia --track-allocation=user filename.jl
), I found thatBase.circshift
took up the most memory.After some searching, I found this package, and by using this package, the memory consumption problem was solved.
Base.circshift
: "6.694 s (3507 allocations: 2.55 GiB)" allocation count (estimate using--track-allocation
flag):2617296789 @views f[:, :, k] .= circshift(f[:, :, k], [cx[k], cy[k]])
ShiftedArrays.circshift
: "5.533 s (3003 allocations: 137.50 MiB)" allocation count:72000 @views f[:, :, k] .= ShiftedArrays.circshift(f[:, :, k], (cx[k], cy[k]))
reduce 94% memory allocations (estimate using
BenchmarkTools.@benchmark
)Some Notes:
2763v3.0.jl
. (just copy and run, these codes only needsShiftedArrays.jl
&BenchmarkTools.jl
)