use a view here: sum(@view(arr[i:i+r])).
sum(@view(arr[i:i+r]))
try to remove all allocations which are not completely on purpose.