@StrongBad texbook touches on that in quite a few places eg: Therefore if you are fussy about the
appearance of pages, you can expect to do some rewriting of the manuscript
until you achieve an appropriate balance, or you might need to fiddle
with the ^|\looseness| as described in Chapter~14; no automated system will
be able to do this as well as you.