# Adding lights to a scene does not scale

**URL:** <https://forum.babylonjs.com/t/adding-lights-to-a-scene-does-not-scale/62029>\
**Category:** Questions\
**Tags:** lighting, performance, clustered-lighting\
**Created:** [January 6, 2026, 6:52pm UTC](https://forum.babylonjs.com/t/adding-lights-to-a-scene-does-not-scale/62029 "2026-01-06T18:52:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CrashMaster](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/crashmaster/32/23662_2.png) [@CrashMaster](https://forum.babylonjs.com/u/CrashMaster)\
**Post date:** [January 6, 2026, 6:52pm UTC](https://forum.babylonjs.com/t/adding-lights-to-a-scene-does-not-scale/62029/1 "2026-01-06T18:52:12Z")

</div>

Hey there,

I am playing with clustered lights and came across some kind of perf issue, which could be just me not using the API correctly honestly 😆

Basically, you can either create a `ClusteredLightContainer` with an array of point lights, or you can add them as you go later with `addLight`. Using one big array at construction time simply uses `addLight` under the hood so you wouldn’t expect any difference here.

However the time it takes to execute becomes massive when creating the point lights upfront (takes 50s on my laptop):

[https://playground.babylonjs.com/#CSCJO2#73](https://playground.babylonjs.com/#CSCJO2#73)

While adding the point lights as we are creating them is almost instantaneous:

[https://playground.babylonjs.com/#CSCJO2#74](https://playground.babylonjs.com/#CSCJO2#74)

After skimming a bit in the code, it seems like [`scene.addLight`](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/scene.ts#L3211) is doing some stuff that does not scale well as we are adding more lights to the scene (complexity looks roughly `O(#mesh * #light)`, so adding N lights yeilds `O(#mesh * #light^2)`). Adding the lights progressively to the container does not have the same issue because the lights are being removed from the scene at the same time, thus `scene.addLight` never explodes (complexity is more like `O(#mesh)` so adding N lights is linear: `O(#mesh * #light)`).

Maybe changing `lightSources` could help a bit to avoid the `O(#light)` from `indexOf` 🤔

If you want a mesh acting as a light source and use many of light sources, you will want to use clustered lighting and thin instancing at the same time, but:

- thin instancing is faster when uploading the entire buffer at once
- clustered lighting is slower when uploading all new lights at once

If that’s the intended behavior, then maybe I can add some doc 👍

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [January 6, 2026, 9:06pm UTC](https://forum.babylonjs.com/t/adding-lights-to-a-scene-does-not-scale/62029/2 "2026-01-06T21:06:47Z")

</div>

@Evgeni_Popov, can you have a look ? if not, I ll do.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [January 6, 2026, 9:30pm UTC](https://forum.babylonjs.com/t/adding-lights-to-a-scene-does-not-scale/62029/3 "2026-01-06T21:30:55Z")

</div>

At a first glance it would be more a doc issue but I will let @Evgeni_Popov have another look into it

---

<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:** [January 7, 2026, 10:32am UTC](https://forum.babylonjs.com/t/adding-lights-to-a-scene-does-not-scale/62029/4 "2026-01-07T10:32:59Z")

</div>

I think that lights that are to be used in a clustered container should never be added to the scene, as these lights don’t need all the setup we do for regular lights.

So, I created this PR that let’s you pass a flag to the light constructor so that the light is not added to the scene:

> <https://github.com/BabylonJS/Babylon.js/pull/17621>
>
> See https://forum.babylonjs.com/t/adding-lights-to-a-scene-does-not-scale/62029
> …
> 
> It dramatically improves creation of lights for use in a clustered light container if you set this new flag to \*\*true\*\* when creating the light.

It makes your first PG even faster than the second one (after you update the creation of the point light to pass **true** for the 4th parameter)!

[EDIT] I also updated the documentation:

> <https://github.com/BabylonJS/Documentation/pull/1463>
>
> Updated the playground example ID for the Sponza scene and added performance tip…s for clustered lights.

---

<div class="post-metadata">

**Author:** ![CrashMaster](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/crashmaster/32/23662_2.png) [@CrashMaster](https://forum.babylonjs.com/u/CrashMaster)\
**Post date:** [January 7, 2026, 1:54pm UTC](https://forum.babylonjs.com/t/adding-lights-to-a-scene-does-not-scale/62029/5 "2026-01-07T13:54:16Z")

</div>

> [@Evgeni\_Popov](#):
>
> I think that lights that are to be used in a clustered container should never be added to the scene, as these lights don’t need all the setup we do for regular lights.

Yeah that makes a lot of sense! Thanks for the PR that works for me 👌

> [@Evgeni\_Popov](#):
>
> It makes your first PG even faster than the second one

It will run so fast, looking forward to the next engine update 🙂
