Destroying parts with MaterialVariants has quadratic O(n^2) complexity

After moving away from Decals to using MaterialService, my game ran a lot slower, with MicroProfiler showing milisecond-long Destroy calls for a single Part. I have investigated this and narrowed it down to MaterialVariants taking quadratic time to destroy.

First Experienced: April 23rd, 2023 | 12:54 PM UTC
Expected behavior: Destroying parts with MaterialVariants should take linear time
Actual result: Destroying parts with MaterialVariants takes O(n^2) time

Specs:
OS: Windows 10 Pro
CPU: Intel(R) Core™ i7-3740QM CPU @ 2.70GHz
GPU: NVIDIA Quadro K1000M

I have attached a reproduction place file.

Blocks as normal parts

Blocks as parts with material variants

Reproducing the bug in a repro place

The Repro Place File:
repro place.rbxl (42.2 KB)

Reproduction steps:
1- Download the reproduction file
2- Create 5,000 parts with MaterialVariants on, destroy. Repeat with off.
3- Create 40,000 parts with the same method.
4- See the time difference. The 5,000 parts should only be slightly more with it on, while 40,000 parts should be several times greater in length.

5 Likes

We’ve filed a ticket to our internal database, and we’ll follow up when we have an update!

Thanks for the report!

3 Likes

Hello, we have enabled some changes that should make this better/more performant. Let us know if this is still causing issues. Thank you.

1 Like

This topic was automatically closed after 6 days. New replies are no longer allowed.