I'm aware that evaluating a vectorized operation (say, an elementwise 
product of two arrays) will result in the allocation of a temporary array. 
I'm surprised, though, at just how much memory this seems to consume in 
practice -- unless there's something I'm not understanding. Here is an 
extreme example:

julia> a = rand(2); b = rand(2);

julia> @time a .*= b;
elapsed time: 0.505942281 seconds (11612212 bytes allocated)

julia> @time a .*= b;
elapsed time: 1.4177e-5 seconds (800 bytes allocated)

julia> @time a .*= b;
elapsed time: 2.5334e-5 seconds (800 bytes allocated)

800 bytes seems like a lot of overhead given that a and b are both only 16 
bytes each. Of course, this overhead (whatever it is) becomes comparatively 
less significant as we move to larger arrays, but it's still sizeable:

julia> a = rand(20); b = rand(20);

julia> @time a.*= b;
elapsed time: 1.4162e-5 seconds (944 bytes allocated)

julia> @time a.*= b;
elapsed time: 2.3754e-5 seconds (944 bytes allocated)

Can someone explain what's going on here?

Reply via email to