Open mattcbro opened 3 years ago
You can try @code_warntype genprojmat(xdata)
with and without inspectdr()
called to see if you're accidentally including a global variable that you didn't intend to, or if someone odd is happening in Threads.@threads
. If the output differs, then that should be the sign that inspectdr()
is doing something at the top-level that causes the threaded loop to be optimized more poorly.
Aside: Do you have a reason to suspect this is the fault of Julia, Base, or a Stdlib? If not, I don't think you need to file an issue here; you already have one filed on InspectDR.jl.
I presume that the probability of it being the fault of Threads.@threads is low but not zero. Nevertheless in various code configurations the only change that causes the massive slowdown in @threads performance is the call to inspectdr(). Moreover once it's called, even if you do no plotting, @threads is damaged until julia is restarted.
My code contains no global variables outside of those defined in the REPL. Furthermore I've tested the same code with all the function definitions being inside a separate module. genprojmat() has no global variables. Any such variables would have to be in @threads or in inspectdr(), whose internals I know nothing about.
Looks similar to https://github.com/JuliaGraphics/Gtk.jl/issues/503.
@KristofferC It really does look similar. I wonder if using ThreadPools@bthreads mitigates the problem. I'll have to give that a try when I get a chance.
This is a rather obscure but difficult to find interaction between the Threads library and the inspectdr() backend for the Plots library. I have some code that attempts to use a simple @threads for loop to parallelize multiple QR decompositions of a block of raw data.
Calling the inspectdr() initializer will cause the threaded code to run anywhere from 200 to 7000 times slower in this example. The difference for the genprojmat() function timings can be seen by commenting and uncommenting the inspectdr() line. I don't do any plotting in this script.
I'm on linux mint 20.1, 8 core processor. The code follows:
The output of running the script, first with inspectdr() uncommented:
Now with inspectdr() commented out and after restarting julia.