What does “optimally refinancing” mean?? Really. This sounds like spreading FUD.
A perfect decision about financing would need to know future interest rates and how long you will stay in the house.
You start with the 20% of mortgagees that completely fail to refinance even though it would save them money [1] and then move on the other 17% that wait too long to refinance and then the 52% that do so at the wrong rate by using rules of thumb instead of more sophisticated models. [2]
If you'd like to better understand this "FUD", Matt Levine is a much better write than I am: https://archive.is/WljUV
[1] https://www.nber.org/papers/w20401 [2] https://www.econstor.eu/bitstream/10419/96658/1/74522380X.pd...