when we want to exclude some objects to collide with each other which one is better for resources usage, using tags or layers?

for example is it better to do this: (for resources in a small or big project)

private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "something")
            Destroy(collision.gameObject);
    }

or using Layer Collision Matrix to exclude objects to collide?

if there is a better way than those I mentioned, please introduce it.

ty

If you are confident that you can use LayerCollisionMatrix for this, it’s a lot better. You will have to remember to add layers to each object that requires it and to update the matrix each time you add new layer. But results are worth it, it’s more efficient and easier to debug, because you will not be spammed with unnecessary collision messages.