# Improving performance with @sync @async macros

**URL:** <https://discourse.julialang.org/t/improving-performance-with-sync-async-macros/82822>\
**Category:** Performance\
**Created:** [June 15, 2022, 4:54pm UTC](https://discourse.julialang.org/t/improving-performance-with-sync-async-macros/82822 "2022-06-15T16:54:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mauri5566](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mauri5566](https://discourse.julialang.org/u/mauri5566)\
**Post date:** [June 15, 2022, 4:54pm UTC](https://discourse.julialang.org/t/improving-performance-with-sync-async-macros/82822/1 "2022-06-15T16:54:24Z")

</div>

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

```julia
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])
		end
		return res
	end
	return INSR0_opt
end

```

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

Without the macros

```julia
122.962 μs (1073 allocations: 69.00 KiB)

```

With the macros

```julia
154.681 μs (1091 allocations: 69.95 KiB)

```

Edit:

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

---

<div class="post-metadata">

**Author:** ![harshita77](https://avatars.discourse-cdn.com/v4/letter/h/278dde/32.png) [@harshita77](https://discourse.julialang.org/u/harshita77)\
**Post date:** [November 16, 2022, 3:17pm UTC](https://discourse.julialang.org/t/improving-performance-with-sync-async-macros/82822/2 "2022-11-16T15:17:45Z")

</div>

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