BRepBuilderAPI_Copy increases complexity

I encountered a massive increase in processing time for several boolean operations, when using deep copied shapes (BRepBuilderAPI_Copy) instead of the original ones. I attached the brepfiles of an example shape before and after copy. Here are the dumps:

    "TopoDS_Shape": {, "TShape.get()": {"TopoDS_TShape": {"Flags": 14}}, "Location": {"TopLoc_Location": {"Transformation()": {"gp_Trsf": {"loc": {"gp_XYZ": [7.41, 4.25, 0]}, "matrix": {"gp_Mat": [1, 0, 0, 0, 1, 0, 0, 0, 1]}, "shape": 7, "scale": 1}}, "IsIdentity()": 0}}, "Orient": 1}
"TopoDS_Shape": {, "TShape.get()": {"TopoDS_TShape": {"Flags": 15}}, "Location": {"TopLoc_Location": {"Transformation()": {"gp_Trsf": {"loc": {"gp_XYZ": [7.41, 4.25, 0]}, "matrix": {"gp_Mat": [1, 0, 0, 0, 1, 0, 0, 0, 1]}, "shape": 7, "scale": 1}}, "IsIdentity()": 0}}, "Orient": 1}

The number of geometries increases! What is the reason behind this and can I have a copy without increasing complexity?

Attachments: 
Kirill Gavrilov's picture

You sample shape is a quad consisting of 3 edges and 2 vertices (TShape) instanced multiple times.

BRepBuilderAPI_Copy returns a "normalized" copy of input quad consisting of 4 edges and 4 vertices.
With copyGeom=false flag, the new Topology will preserve original Geometry (e.g. it will be shared), and with copyGeom=true the Geometry will be duplicated as well.
This is what BRepBuilderAPI_Copy does by design - it is not a bug or something like this.

Normalized presentation might increase the size of Topology, but it is more straightforward to process and avoid unexpected side effects of sharing.
Consider that you perform a Boolean operation with a Topology intensively sharing shapes in different places - such Topology should be unshared and duplicated anyway to modify only shapes at places touched by another Boolean operand (but of course, this duplication could be done locally, not for all instances of shared shape).

You may consider extending BRepBuilderAPI_Copy functionality with a flag, creating a copy of input Shape with nested sharing properties preserved.
Patches improving OCCT are welcome!