gumyr / build123d

A python CAD programming library
Apache License 2.0
380 stars 72 forks source link

Builder mode performance issues #612

Open MatthiasJ1 opened 2 months ago

MatthiasJ1 commented 2 months ago

In the following example, the Builder version is 16x slower:

with print_time():
    p = Cylinder(20, 20)
    p += TrapezoidalThread(2*20+2, 2, 60, 10)

with print_time():
    with BuildPart() as p2:
        Cylinder(20, 20)
        TrapezoidalThread(2*20+2, 2, 60, 10)

gives:

0.5091060638427734s
8.107296800613403s
gumyr commented 2 months ago

This is very interesting - the difference in time is just in time it takes to call TrapezoidalThread. The Algebra result also looks correct while the Builder version is missing some of the thread - curious! Some good clues here.

jdegenstein commented 2 months ago

Here's another slightly tweaked version, that predictably works more quickly and interestingly is not missing any thread:

from build123d import *
from bd_warehouse.thread import *
import time
start_time = time.time()
th = TrapezoidalThread(2*20+2, 2, 60, 10)
with BuildPart() as p3:
    Cylinder(20, 20)
    add(th)
print("--- %s seconds ---" % (time.time() - start_time))

Time is approximately 2x the algebra version above.