Brep.CreateBoolean... performances V8 vs. V7

Create the model with this Python 2 script.
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import scriptcontext as sc


def main():
    
    points = rs.coerce3dpointlist((
        ( 0.0,  0.0,  0.0),
        ( 0.0,  5.0,  0.0),
        ( 0.0, 10.0,  0.0),
        ( 5.0,  0.0,  0.0),
        ( 5.0,  5.0, 10.0),
        ( 5.0, 10.0,  0.0),
        (10.0,  0.0,  0.0),
        (10.0,  5.0,  0.0),
        (10.0, 10.0,  0.0),
        ))
    
    ns = rg.NurbsSurface.CreateFromPoints(
        points,
        uCount=3,
        vCount=3,
        uDegree=2,
        vDegree=2)
    
    brep = ns.ToBrep()
    
    breps = []
    for i in range(100):
        for j in range(100):
            brep_Trans = brep.DuplicateBrep()
            brep_Trans.Translate(rg.Vector3d(10.0*i, 10.0*j, 0.0))
            breps.append(brep_Trans)
    
    brep_Joined = rg.Brep.JoinBreps(breps, tolerance=2*sc.doc.ModelAbsoluteTolerance)[0]
    
    sc.doc.Objects.AddBrep(brep_Joined)
    
    sc.doc.Views.RedrawEnabled = False
    
    rs.AddCylinder((5,5,0), height=10, radius=2, cap=True)
    
    sc.doc.Views.RedrawEnabled = True


if __name__ == '__main__': main()
Test the model with this Python 2 script.

from future import absolute_import, division, print_function, unicode_literals

import Rhino
import Rhino.Geometry as rg
import rhinoscriptsyntax as rs
import scriptcontext as sc

from System.Diagnostics import Stopwatch

def main():

gA = rs.GetObject("Select brep A", filter=rs.filter.polysurface, preselect=True)
if gA is None: return

gB = rs.GetObject("Select brep B", filter=rs.filter.polysurface)
if gB is None: return

rgA_In = rs.coercebrep(gA)
rgB_In = rs.coercebrep(gB)

Rhino.RhinoApp.SetCommandPrompt("Working ...")

sw = Stopwatch()

sMethods = (
    "rg.Brep.CreateBooleanUnion([rgA_In, rgB_In], tolerance=2.0*sc.doc.ModelAbsoluteTolerance)",
    "rg.Brep.CreateBooleanDifference(rgA_In, rgB_In, tolerance=2.0*sc.doc.ModelAbsoluteTolerance)",
    "rg.Brep.CreateBooleanIntersection(rgA_In, rgB_In, tolerance=2.0*sc.doc.ModelAbsoluteTolerance)",
    )

for sMethod in sMethods:
    sw.Restart()
    
    rgB_Res = eval(sMethod)
    
    sw.Stop()
    
    print("{} ms for {}".format(sw.ElapsedMilliseconds, sMethod.split('(')[0]))
    
    if rgB_Res is None:
        print("{} failed.".format(sMethod.split('(')[0]))

if name == ‘main’: main()

Picking the larger brep for brep A and the cylinder for brep B, I get these results:

8.8.24163.12481, 2024-06-11

2951 ms for rg.Brep.CreateBooleanUnion
2999 ms for rg.Brep.CreateBooleanDifference
260 ms for rg.Brep.CreateBooleanIntersection

7.37.24107.15001, 2024-04-16

215 ms for rg.Brep.CreateBooleanUnion
2835 ms for rg.Brep.CreateBooleanDifference
247 ms for rg.Brep.CreateBooleanIntersection

Picking the breps in reverse (cylinder then other):

8.8.24163.12481, 2024-06-11

2981 ms for rg.Brep.CreateBooleanUnion
216 ms for rg.Brep.CreateBooleanDifference
214 ms for rg.Brep.CreateBooleanIntersection

7.37.24107.15001, 2024-04-16

233 ms for rg.Brep.CreateBooleanUnion
505 ms for rg.Brep.CreateBooleanDifference
214 ms for rg.Brep.CreateBooleanIntersection

I didn’t include them in the test, but the UI commands, _BooleanUnion, _BooleanDifference, and _BooleanIntersection, all execute in significantly less times in both V7 and V8.

Hi @spb,

Have you benchmarked Python3 in V8?

– Dale

8.8.24170.13001, 2024-06-18 Python3 results are similar to Python2 in V8.

Picking large brep then cylinder:

2866 ms for rg.Brep.CreateBooleanUnion
2944 ms for rg.Brep.CreateBooleanDifference
251 ms for rg.Brep.CreateBooleanIntersection

Picking cylinder then large brep:

2916 ms for rg.Brep.CreateBooleanUnion
214 ms for rg.Brep.CreateBooleanDifference
213 ms for rg.Brep.CreateBooleanIntersection

Hi @spb,

The results you’re getting are not a whole lot different than what I’m getting.

results.txt (1.1 KB)

– Dale

So, V8’s RhinoBooleanUnion and rg.Brep.CreateBooleanUnion take about 10x the time of V7 to complete. I didn’t find a relevant issue in YouTrack.

I’m getting there.

https://mcneel.myjetbrains.com/youtrack/issue/RH-82742

– Dale

Hi @spb,

We’ve pushed a fix into Rhino that will appear in Rhino 8 SR10. When you see a release candidate available, you might give it a go.

– Dale

1 Like