About PainterSortCompare method

    // packages/dev/core/src/Rendering/renderingGroup.ts
    public static PainterSortCompare(a: SubMesh, b: SubMesh): number {
        const meshA = a.getMesh();
        const meshB = b.getMesh();

        if (meshA.material && meshB.material) {
            return meshA.material.uniqueId - meshB.material.uniqueId;
        }

        return meshA.uniqueId - meshB.uniqueId;
    }

I wonder why the list is sorted by material and geometry before rendering?

It is first sorted by material to limit the number of state changes at WebGL level.

If the two meshes have no materials, we simply sort them by their uniqueId, which corresponds to the order in which they were created.