-
-
Notifications
You must be signed in to change notification settings - Fork 112
copy.copy on a Shape is surprisingly slow #953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Nevermind my "fix" definitely breaks other things. Back to the drawing board then :/ |
Okay so it seems like the cadquery OCP does not expose the proper initializer for TopoDS_Shape to be able to copy it (https://github.com/Open-Cascade-SAS/OCCT/blob/876ccbe977a7a8d4910e68fd6b3536645818ed0e/src/ModelingData/TKBRep/TopoDS/TopoDS_Shape.hxx#L53). We can easily get around that by just using .Located() which calls it for us. So I think a proper copy function looks like this:
$ uv run -m timeit -s "import build123d,copy;screw=build123d.import_step('M6-1x12-countersunk-screw.step')" "copy.copy(screw)"
20000 loops, best of 5: 17.6 usec per loop |
There was no attempt to make the |
Oh my mistake then, hope it is still a welcome improvement. I am unsure of how Would you be interested in a PR with this change assuming I write the proper tests necessary? |
Using
copy.copy
on aShape
to create a shallow copy of the shape is a lot slower than I would have imagined from the documentation at https://build123d.readthedocs.io/en/latest/assemblies.html which implies that it is very very fast.Example:
This seems to imply that is not actually faster to make a shallow copy rather than a deep one. When actually outputting to a .step as in the documentation example, it is still MUCH faster however, so that is true, but I still found this behavior to be weird.
Looking into the code, it seems that
__copy__
actually callsdeepcopy
:Is there a good reason to be doing things this way? I tried replacing it with the following, and so far I'm not seeing any issues:
Is this a bug for is there some purpose to the deepcopy that I have missed?
I found this behavior when trying to improve the
export_step
to more accurately apply labels to shapes (see issue [NOT SUBMITTED YET] and possibly fix #301 while I'm at it, as well as foundation for #296, where it is important that TShapes are preserved when possible, and the current copy code seems to somehow break that - although I'm unsure exactly why.The text was updated successfully, but these errors were encountered: