Skip to content

Commit 4800158

Browse files
authored
make spawn faster by fixing the sync context check (#33885)
1 parent 193f3e8 commit 4800158

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

base/task.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ macro async(expr)
350350
var = esc(sync_varname)
351351
quote
352352
local task = Task($thunk)
353-
if $(Expr(:isdefined, var))
353+
if $(Expr(:islocal, var))
354354
push!($var, task)
355355
end
356356
schedule(task)

base/threadingconstructs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ macro spawn(expr)
115115
quote
116116
local task = Task($thunk)
117117
task.sticky = false
118-
if $(Expr(:isdefined, var))
118+
if $(Expr(:islocal, var))
119119
push!($var, task)
120120
end
121121
schedule(task)

src/julia-syntax.scm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,10 @@
24952495
(call (top setindex!) ,d ,var (quote ,v)))))
24962496
names)
24972497
,d)))
2498+
((eq? (car e) 'islocal)
2499+
(if (memq (var-kind (cadr e) scope) '(global none))
2500+
'false
2501+
'true))
24982502
((eq? (car e) 'lambda)
24992503
(let* ((args (lam:vars e))
25002504
(body (resolve-scopes- (lam:body e) (make-scope e args '() '() sp '() scope))))

stdlib/Distributed/src/macros.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ macro spawn(expr)
4848
var = esc(Base.sync_varname)
4949
quote
5050
local ref = spawn_somewhere($thunk)
51-
if $(Expr(:isdefined, var))
51+
if $(Expr(:islocal, var))
5252
push!($var, ref)
5353
end
5454
ref
@@ -93,7 +93,7 @@ macro spawnat(p, expr)
9393
end
9494
quote
9595
local ref = $spawncall
96-
if $(Expr(:isdefined, var))
96+
if $(Expr(:islocal, var))
9797
push!($var, ref)
9898
end
9999
ref
@@ -346,7 +346,7 @@ macro distributed(args...)
346346
syncvar = esc(Base.sync_varname)
347347
return quote
348348
local ref = pfor($(make_pfor_body(var, body)), $(esc(r)))
349-
if $(Expr(:isdefined, syncvar))
349+
if $(Expr(:islocal, syncvar))
350350
push!($syncvar, ref)
351351
end
352352
ref

0 commit comments

Comments
 (0)