There’s a few threads about this, but the short version is that ports vent gas off so that there’s less perceived recoil since there is less gas (and mass) following the bullet out the barrel. These are usually most effective somewhere around 2-4” in a revolver.
Alec, hit us with a picture of effective ports.
Compensators collect the gas in a chamber, let it expand, then force it up to fight against rise.
Ports reduce felt recoil, comps oppose muzzle rise.
Here’s a properly compensated gun: