http://coldfusion.com logo
#lucee
Title
# lucee
g

gratzc

05/05/2022, 4:51 PM
does anyone know on an arrayEach with threads, do the variables created outside the thread but used inside get duplicated within each thread? Seeing a bit of a memory issue when i use the threaded arrayEach, it was working but until i added a large variable that was needed to be used inside the loop.
b

bdw429s

05/05/2022, 5:54 PM
@gratzc Lucee or Adobe?
While CFThread on Adobe historically has duplicated all attributes passed in, I'm not aware of any such behavior in arrayEach()
Do you have code to repro this?
Generally speaking, when you do
Copy code
outsideVar = 'foo';
[1,2].each( ()=>{ echo(outsideVar) }, true )
The
outsideVar
variable is not being duplicated, but just accessed directly via lexical scopin
g

gratzc

05/05/2022, 6:32 PM
Lucee, and what you have is basically it yes, just outsideVar is a large struct.
b

bdw429s

05/05/2022, 6:36 PM
So are you positive it's duplicating or is that just a guess?
g

gratzc

05/05/2022, 6:36 PM
right a feeling
b

bdw429s

05/05/2022, 6:37 PM
Doesn't look duplicated to me
https://trycf.com/gist/04c2da03025ac1547e74faa97d2e2f62/lucee5?theme=monokai
Copy code
outsideVar = { "brad" : "wood" };
[1].each( ()=>{ outsideVar.curt='gratz'; }, true )
dump(outsideVar)
Changes inside the threaded calls are directly modifying the original struct
I'll add there can be a lot of overhead for very large arrays in parallel, especially if the processing on each item is very small
Are you sure the only thing that changed was the size of the struct?
g

gratzc

05/05/2022, 6:38 PM
thats what was introduced, and generating the struct from an http call
7 Views