does anyone know on an arrayEach with threads, do ...
# lucee
g
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
@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
Lucee, and what you have is basically it yes, just outsideVar is a large struct.
b
So are you positive it's duplicating or is that just a guess?
g
right a feeling
b
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
thats what was introduced, and generating the struct from an http call