Skip to content

Fix issue with O(N^2) performance issue for addPart#17928

Merged
CedricGuillemet merged 26 commits intoBabylonJS:masterfrom
spsDrop:fix/improve-n2-add-part-loading
Apr 1, 2026
Merged

Fix issue with O(N^2) performance issue for addPart#17928
CedricGuillemet merged 26 commits intoBabylonJS:masterfrom
spsDrop:fix/improve-n2-add-part-loading

Conversation

@spsDrop
Copy link
Copy Markdown
Contributor

@spsDrop spsDrop commented Feb 19, 2026

Everytime we add a part we re-call _makeSplat for every part and every splat in those parts. This results in a worsening and worsening load time instead of an expected linear growth. Here is a performance flame graph showing the growing number of calls after adding 4 splats together.

image

Copy link
Copy Markdown
Contributor

@eliemichel eliemichel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it would be easier and less invasive to change from addPart() to addParts(), then make sure to allocate mergedSplatsData only once in there with all the parts in it. You then only have a single call to this.updateData and thus only one call to _makeSplat.

The main drawback of my proposal is if you do not know ahead of time the full list of parts that you want to load and end up addParts() with a single part each time then you gain nothing and your approach is probably better.

Comment thread packages/dev/core/src/Meshes/GaussianSplatting/gaussianSplattingMesh.ts Outdated
@spsDrop spsDrop marked this pull request as draft February 20, 2026 10:06
@sebavan
Copy link
Copy Markdown
Member

sebavan commented Feb 23, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Feb 23, 2026

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Feb 23, 2026

Snapshot stored with reference name:
refs/pull/17928/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/17928/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/17928/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/17928/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/17928/merge
https://gui.babylonjs.com/?snapshot=refs/pull/17928/merge
https://nme.babylonjs.com/?snapshot=refs/pull/17928/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/17928/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Feb 23, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Feb 23, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Feb 23, 2026

Jesse Foltz added 2 commits March 2, 2026 16:40
- Change parts to always store data to textures and rebuild textures on remove
@Popov72
Copy link
Copy Markdown
Contributor

Popov72 commented Mar 4, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@spsDrop spsDrop marked this pull request as ready for review March 6, 2026 20:24
@spsDrop spsDrop requested a review from eliemichel March 6, 2026 20:39
@sebavan
Copy link
Copy Markdown
Member

sebavan commented Mar 6, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 6, 2026

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 6, 2026

Reviewer - this PR has made changes to one or more package.json files.

@sebavan
Copy link
Copy Markdown
Member

sebavan commented Mar 6, 2026

Thanks a lot for the fix.

Moving as draft until @CedricGuillemet has a chance to review and decide if we can/should merge pre or post 9.0

@sebavan sebavan marked this pull request as draft March 6, 2026 21:12
@sebavan
Copy link
Copy Markdown
Member

sebavan commented Mar 6, 2026

Adding @RaananW / @ryantrem to understand how this could happen
image

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 6, 2026

Snapshot stored with reference name:
refs/pull/17928/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/17928/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/17928/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/17928/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/17928/merge
https://gui.babylonjs.com/?snapshot=refs/pull/17928/merge
https://nme.babylonjs.com/?snapshot=refs/pull/17928/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/17928/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 6, 2026

Smart Filters Editor is available to test at:
https://sfe.babylonjs.com/?snapshot=refs/pull/17928/merge

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 6, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 27, 2026

@Popov72
Copy link
Copy Markdown
Contributor

Popov72 commented Mar 27, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 27, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 27, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 27, 2026

@sebavan
Copy link
Copy Markdown
Member

sebavan commented Mar 30, 2026

@spsDrop I think you may need to merge with master

@CedricGuillemet
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@Popov72
Copy link
Copy Markdown
Contributor

Popov72 commented Mar 30, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 30, 2026

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 30, 2026

Snapshot stored with reference name:
refs/pull/17928/merge

Test environment:
https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/17928/merge/index.html

To test a playground add it to the URL, for example:

https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/17928/merge/index.html#WGZLGJ#4600

Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves):

https://playground.babylonjs.com/?snapshot=refs/pull/17928/merge
https://sandbox.babylonjs.com/?snapshot=refs/pull/17928/merge
https://gui.babylonjs.com/?snapshot=refs/pull/17928/merge
https://nme.babylonjs.com/?snapshot=refs/pull/17928/merge

To test the snapshot in the playground with a playground ID add it after the snapshot query string:

https://playground.babylonjs.com/?snapshot=refs/pull/17928/merge#BCU1XR#0

If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools.

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 30, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 30, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Mar 30, 2026

@CedricGuillemet
Copy link
Copy Markdown
Contributor

@spsDrop It's working great with a little issue regarding visibility. Value is not taken into account: https://playground.babylonjs.com/?snapshot=refs/pull/17928/merge#BTS11N#0

@spsDrop
Copy link
Copy Markdown
Contributor Author

spsDrop commented Mar 31, 2026

OK fixed the bug with preserving transparency on remove. And integrated your PR in the new base class

@CedricGuillemet
Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 1, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 1, 2026

@bjsplat
Copy link
Copy Markdown
Collaborator

bjsplat commented Apr 1, 2026

@CedricGuillemet CedricGuillemet merged commit 6629c50 into BabylonJS:master Apr 1, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants