An efficient method to compute the residual phase on a Lefschetz thimble