Technology Connections has a pretty good rundown of how electric hot water heaters work.
You’re using hot water at X gallons per minute while the heater can heat Y<X gallons a minute but the water is extracted from the top of the tank so it stays fairly hot until you’ve used more than half of the tank, then drops like a rock at the end when the supply is exhausted.
Anything that warms the cold water going to your shower slightly reduces the rate of hot water use, which extends the amount of time before you run out, which is more time to heat more water.