The underlying physics system doesn’t know anything about Unity colliders, it’s just physics shapes so it won’t have any effect on contact generation. For instance, a CircleCollider2D just produces a circle shape, a BoxCollider2D produces a single polygon shape, a PolygonCollider2D just produces multiple polygon shapes etc. Polygon shapes created with a PolygonCollider2D or a BoxCollider2D are identical, they are just polygon shapes.
Contacts are obviously only produced when there’s an overlap between shapes on different colliders so it’s as simple as that. If you have 10,000 shapes in a collider, it wouldn’t matter. It’d only matter if all those shapes overlapped another collider and you were asking for contacts. The profiler shows how many contacts are being produced too so maybe look at that as you’re likely to have a lot being produce. Impossible to really say more.
In terms of the code you posted, you don’t need to disable the CustomCollider2D because it is not doing what the PolygonCollider2D is doing. The PolygonCollider2D takes in outlines (paths) which the physics system knows nothing about. These have to be tessellated into convex polygons (real physics polygon shapes). That takes time. If you set multiple paths, it keeps doing this each call.
The CustomCollider2D doesn’t interpret paths because it takes real shapes and can create/update them as is. No intermediary work required. When you set the shapes, it’ll even check each shape to see if it already exists and not modify it but whatever it does, it does quickly. If you change the radius/vertex on a shape, it can change that single thing alone without it affecting anything else; this is the reason for it being quick alongside being able to accept a new list of shapes and being able to ignore ones that have no changed etc.
The way you should be using it is using a PhysicsShapeGroup2D. You create whatever you need in that, then just provide it that. The shape group has things like AddBox, AddPolygon etc. If you reuse the shape group, it’ll not allocate too as its capacity will automatically increase. Note: There’s a bug which has been fixed and is waiting to land that fixes a small GC allocation here.
Of course, as you show, there’s an overload to SetCustomShapes that allows you to provide even lower-level raw native array shapes/vertices but it requires more attention to detail as the code example shows.
If you have a simple reproduction case you could create in a project then feel free to send it me either DM me or if you like, DM me with your email address and I can set-up a private place for you to upload it.