There is a huge difference between computing if two elements intersect with one another and computing the join element for every possible pair.

Moreover, as you have written it, your graph seem wrong : you are joining geometry by cross product lacing, meaning that you are joining 1 and 1, then 1 and 2, then 1 and 3, then 1 and 4 etc. then 1 and n, then 2 and 1, then 2and 2 etc. then 2 and n, … then n and 1, etc… then n and n.

At no moment you are joining all of your elements together. If it was the case, you would have to put one input in your fonction, the list of your elements.