How to change BoxGeometry visibility in InstancedMesh

Hi, due to very poor performance caused by the sheer amount of BoxGeometries in my 3D project I switched to InstancedMesh, which greatly reduced the lag, but I found out the performance could be even greater if all the unnecessary faces would be just not rendered. Everything I tried though had no effect and the faces still kept rendering, I guess this has to be done in a very different way to how I am doing it atm. Solution which I used before InstancedMesh simply went through all the BoxGeometries, checked if there is one next to each other and based on that hid the needed face. This is now, I guess impossible and rather needs completely different approach. Is it even possible? And if so, how can I do that?