When I implemented a foot IK system, I used a raycast each frame to determine the position of the ground in front of the foot. I used the raycast for all types of movement and it worked fine for my purposes. Performance shouldn't be an issue if you don't have too many units doing the raycast at once ("too many" depends on your target platform and how hard your game pushes the physics engine). If there might be hundreds of units all simultaneously walking around with IK, you might enable/disable the raycast foot placement based on the distance from the camera (in other words, if the unit is too far away for the player to be able to tell whether their foot IK is accurate, you don't need to perform the raycast).
Obviously, you should use layer masks to ensure the IK raycast only checks your terrain layer (or any other layers containing walkable surfaces)
I found it necessary to start the raycast a little bit above the foot. If you start the raycast right at the foot, but the foot has clipped through the terrain, the raycast won't detect the terrain because it's starting below the terrain. If you start the raycast above the foot, that's not an issue. How far above the foot depends on your specific leg animations and how your terrain is shaped, but a good starting point is the distance from knee to foot. For example, if the character's leg is .5 meters inches from heel to knee, you might start the raycast .5 meters above the foot.
The free "Fast IK" asset on the Unity Asset Store includes an example of combining IK with Mecanim animation. I used a different solution but found it helpful for reference: https://assetstore.unity.com/packages/tools/animation/fast-ik-139972
Unity has a built-in "foot IK" option for humanoid Mecanim animations but they don't really describe it in their documentation and I haven't used it before. If you haven't already looked into it, you should see if it meets your needs.