In our project, we have models with about 500 objects but much fewer segmentation instances, and when calculating segmentations repeatedly, we had a very annoying performance problem. Each render iteration gets a bit slower kinda linearly.
After some investigation, we discovered that when this library kicks in it creates one material for each object but every time a render is requested it creates another material instead of reusing the one already there.
This pull request changes this behavior by creating one material per _instid instead of per object and check if the material is already created so it will not be created again reusing that material and avoiding the slowdown.
In our project, we have models with about 500 objects but much fewer segmentation instances, and when calculating segmentations repeatedly, we had a very annoying performance problem. Each render iteration gets a bit slower kinda linearly.
After some investigation, we discovered that when this library kicks in it creates one material for each object but every time a render is requested it creates another material instead of reusing the one already there.
This pull request changes this behavior by creating one material per _instid instead of per object and check if the material is already created so it will not be created again reusing that material and avoiding the slowdown.