react-postprocessing
react-postprocessing copied to clipboard
Performance-bug with `<Select />`
Hi and thank you for your fantastic work on this project.
I've just encountered what I believe is a performance bug with the <Select />
component. In this trivial example, I get a CPU usage of 100%:
<Canvas>
<Selection>
<Select enabled>
<Box name="box" />
</Select>
</Selection>
</Canvas>
The react profiler says that the culprit is in the Selection / Select component:
I see two issues with this component:
-
this condition is always true, which is why a call to
select
is triggered every time this hook runs. In my case, this condition is always true for the<group />
inside the<Select />
component. But more generally, I think it would be true for every non-Mesh in the tree. -
here, the value of
api
is the "old" value, i.e. the value beforeapi.select()
was executed. Importantly, in my case,api.selected
is always an empty array. Therefore, I believe the update of the selected objects shouldn't happen in a useEffect cleanup handler.