# About PainterSortCompare method

**URL:** <https://forum.babylonjs.com/t/about-paintersortcompare-method/42248>\
**Category:** Questions\
**Tags:** optimization, rendering\
**Created:** [July 8, 2023, 6:24am UTC](https://forum.babylonjs.com/t/about-paintersortcompare-method/42248 "2023-07-08T06:24:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KevinWu](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/kevinwu/32/33060_2.png) [@KevinWu](https://forum.babylonjs.com/u/KevinWu)\
**Post date:** [July 8, 2023, 6:24am UTC](https://forum.babylonjs.com/t/about-paintersortcompare-method/42248/1 "2023-07-08T06:24:30Z")

</div>

```auto
    // 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?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [July 9, 2023, 8:55am UTC](https://forum.babylonjs.com/t/about-paintersortcompare-method/42248/2 "2023-07-09T08:55:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fazil47](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/fazil47/32/38879_2.png) [@fazil47](https://forum.babylonjs.com/u/fazil47)\
**Post date:** [July 3, 2025, 8:40am UTC](https://forum.babylonjs.com/t/about-paintersortcompare-method/42248/3 "2025-07-03T08:40:53Z")

</div>

@Evgeni_Popov then is passing in a noOp function for sorting fine? this method is taking too much time.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/f/1f16b26f66028427f6c78743ab42cbd59e18fbb0.png)

Frame time is a little better after doing this:

```ts
const noOp = () => {};
scene.setRenderingOrder(0, noOp, noOp, null);
scene.setRenderingOrder(1, noOp, noOp, null);
scene.setRenderingOrder(2, noOp, noOp, null);
scene.setRenderingOrder(3, noOp, noOp, null);

```

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [July 3, 2025, 11:18am UTC](https://forum.babylonjs.com/t/about-paintersortcompare-method/42248/4 "2025-07-03T11:18:34Z")

</div>

That’s entirely possible. If it’s quicker without sorting, go ahead!
