Skip to content

Commit b006695

Browse files
andrebsguedesRAI CI (GitHub Action Automation)
authored andcommitted
Makes IntrusiveLinkedListSynchronized mutable to avoid allocation on poptask (JuliaLang#50802)
Currently `poptask` is allocating every time it calls into `jl_task_get_next` due to `StickyWorkqueue` (`IntrusiveLinkedListSynchronized`) being immutable and requiring an allocation to be used as `Any` on the `ccall`. The allocations can be seen in the following snippet: ``` function work() done = 0.0 l = Threads.SpinLock() Threads.@sync for _ in 1:(Threads.nthreads() / 2) Threads.@Spawn begin v = 1.0 for i in 1:(1<<33) v *= 1.0001 if i % (1 << 13) == 0 yield() end end Base.@lock_nofail l done += v end end return done end julia> @time work() 15.758794 seconds (5.03 M allocations: 153.523 MiB, 0.35% gc time) ``` Which after the change becomes: ``` julia> @time work() 15.907513 seconds (67 allocations: 4.719 KiB) ```
1 parent 1ac9c81 commit b006695

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/task.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ end
688688

689689
## scheduler and work queue
690690

691-
struct IntrusiveLinkedListSynchronized{T}
691+
mutable struct IntrusiveLinkedListSynchronized{T}
692692
queue::IntrusiveLinkedList{T}
693693
lock::Threads.SpinLock
694694
IntrusiveLinkedListSynchronized{T}() where {T} = new(IntrusiveLinkedList{T}(), Threads.SpinLock())

0 commit comments

Comments
 (0)