I've heard people use these terms, interchangeably. Since good definitions make for clear ideas I wanted to explicitly define them.
Refactoring: Restructuring computer code (factors), without changing its external behavior (functionality), to make it more readable, or change its design, reduce complexity, etc.
Porting: Changing code so it’ll run in a different execution environment (language, operating system, CPU, etc) than originally designed for. This makes the code more "portable."
Optimizing: Modifying code to be more efficient without changing its functionality so it runs faster or uses less memory, etc.
Frequently, code changes focusing on one of these areas will have other benefits. For example, when porting code, it might also be optimized and refactored.