Based on the results of profiling the code, a very significant source of overhead is the ClippableMesh causing PoolVector reallocations. The memory access should be reworked with the following in mind:
The PoolVector in question holds faces that get generated when clipping objects to the plane of the water. The number of generated faces is not known in advance, but we could pre-allocate the PoolVector with enough memory for the worst-case scenario.
The PoolVector gets recreated every physics frame. Once the PoolVector pre-allocation is in place, we should be able to clear and reuse that same PoolVector instead.
The ClippableMesh itself gets recreated every physics frame due to working in global coordinates. A better approach would be to create the ClippableMesh only once, and reapply the global transform every physics frame.
Based on the results of profiling the code, a very significant source of overhead is the ClippableMesh causing PoolVector reallocations. The memory access should be reworked with the following in mind: