I am using C++ to write a CPG plugin,when using ShapeRange.Group in CorelDRAW to group 2,000 objects, it takes 30 seconds.

I am using C++ to write a CPG plugin. There are tens of thousands of overlapping objects that need to be grouped. The C++ algorithm runs very quickly, in less than 0.25 seconds. However, when using ShapeRange.Group in CorelDRAW to group 2,000 objects, it takes 30 seconds. How can I solve the software bottleneck?