Parallel processing time destroyed by sending signals from serial to parallel and back via BindableEvents

Hello all, I’m making a segment intersector module that is able to handle finding intersections between segments in O(nlogn) time. I achieved this by using the Bentley-Ottmann algorithm to find segment intersections, and I also use a spatial QuadTree that contains segments within its leaf nodes so I can partition the intersection calculations into multiple regions for parallel processing.

Now, I tried implementing the parallel processing part, but I found out that sending signals from serial to parallel takes a significant amount of time. Thats even without sending any arguments through a Bindable Event.

image

You can see in this image that the normal serial time to calculate intersections is 0.015 seconds. Sending a signal from serial to parallel takes around 0.014 seconds max (already the same amount of time it took to find all the intersections in serial). The actual parallel execution of finding intersections takes half the time it took for serial, around 0.006 seconds max (performance boost I was looking for), but then sending a signal from parallel back to serial takes 0.39 seconds max, which completely destroys the purpose of using parallel processing to speed up the calculations.

I know some may be thinking, “well, is it enough segments to even be useful?” Maybe the overhead of sending a small amount of segments defeats the purpose for using parallel processing to speed up the process. However, this happens even when I compute 2000 or 3000 segment intersections. The amount of overhead it takes to send a signal to parallel processing VMs and back takes a very significant amount of time.

This is the image of what’s actually happening:

Does anyone know why this could be happening?

2 Likes

There is an overhead to parallelization, but it should not take that long. I’m not sure how you’re benchmarking it.

However, you’re right when you say that you’re not calculating enough to actually reap the benefits. 2000-3000 segment operations is minimal. You can do millions of mathematical operations before there are any performance differences. Here’s a diagram of stress on the main thread when using and not using parallel:

Parallel computing has some overhead, but at a certain point, it will be faster than serial.

If I’m not wrong, the main thread has to wait for parallel threads to complete before advancing the frame, so overstressing parallel threads will also affect the main thread as well.

1 Like

Thanks for the response!

The thing is in my benchmarking, I am seeing the performance boost from the parallel processing, but the overhead from sending data through BindableEvents is a crazy amount of overhead that it doesn’t even make sense to use parallel processing. It takes .01 seconds to calculate 2048 segment intersections, but it only takes .003 seconds to find intersections for 2048 segments in clustered partitions.

The last value for the benchmarking is the entire time it takes to send signals back and forth.