didn't look at it that closely), other than to say tree data structure is helping you and hurting you.
What I did to fix the file was work backwards. Looking at only the left panel you are trying to create 11 total planar surfaces from edge curves (8 curves per surface). That means you should be generating 11 of each type of curve so that you will have 88 total curves when you attempt to join them.
Tree data was in some cases giving you 121 of each type of curve (lists matching with tree structure...) so I worked backwards from your individual curves to flatten the inputs until ending up with only 11 (the expected number) of each type of curve.
…
pen Brep"; I didn't know it worked on flat surfaces. And I think it's only fair to include in your benchmark the considerable time 'SUnion' takes in this example: 21.9 seconds for 121 rings and likely much more with 400 or 1,000+ rings.
Then I noticed the pattern doesn't match. Checked the circles and they are the same. The distance between them, however, is different: 7 instead of 6. When I change that value to 6, the Python fails badly. All the holes and gaps are gone, which destroys the pattern:
I can't do the "two phase" approach on an 11 X 11 grid, but I can do 6 X 6 and 2 X 2 to get a 12 X 12 grid (40 'SUnion' operations) in 28 seconds total. That beats your benchmark of ~37 seconds for an 11 X 11 grid, if you include the 'SUnion' in your code.
…