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 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.