Improving performance with @sync @async macros

I’m trying to parallelize this function by using @async @sync

function INSR_opt(f)
	function INSR0_opt(seq)
		len = length(seq)
		res = seq[end]
		@inbounds @sync for i in range(len-2,step=-1,stop=0)
			@async res = f([seq[i+1], res])
		return res
	return INSR0_opt

The way I’m using the macros seems correct to me but the performance just gets worse

Without the macros

122.962 μs (1073 allocations: 69.00 KiB)

With the macros

154.681 μs (1091 allocations: 69.95 KiB)


I’ve tried using @spawn instead of @async but the performance still won’t improve.

I think there would be chances of having race condition in your code.