While waiting for one of those seemingly interminable Grasshopper definitions to compute for a project, you know, the one where you force-feed the SDiff component with hundreds of panels, each with hundreds of custom perforations, I thought there had to be a faster way. And of course, I thought multi-threading would be it. Unfortunately, boolean operations are notoriously difficult (if not impossible) to run as parallel.
And though it is true we can not multi-thread solid boolean methods, we can, however, spread branches of inputs across threads (thank you data trees). For example, when perforating individual panels, each with their own set of shapes to be differenced, you can run the boolean process for each panel on it’s own thread. It’s not truly multi-threading the boolean operation, but still runs much faster for the branched use case. In fact, I imagine this could help any component that could not otherwise be multi-threaded.
Here is a generic swiss-cheese example with 64 slices:
The boolean difference method employed in the definition is done recursively so that any shapes that fail to difference can be discarded to a list that can be used for troubleshooting without dumping the whole process (sphere in red). This takes a little longer than difference-ing the whole list at once, but it’s negligible and the troubleshooting benefit has proven useful for me.
Here is the Grasshopper definition for the swiss-cheese example:
After searching a bit more following this post to discourse.mcneel.com, I found djordje posted an extremely elegant version of this approach for Python way back in 2014!