The optimal energy amplifications of streamwise-uniform and spanwise-periodic perturbations of the hyperbolic-tangent mixing layer are computed and found to be very large, with maximum amplifications increasing with the Reynolds number and with the spanwise wavelength of the perturbations. The optimal initial conditions are streamwise vortices and the most amplified structures are streamwise streaks with sinuous symmetry in the cross-stream plane. The leading suboptimal perturbations have opposite (varicose) symmetry. When forced with finite amplitudes these perturbations modify the characteristics of the Kelvin–Helmholtz instability. Maximum temporal growth rates are reduced by optimal sinuous perturbations and are slightly increased by varicose suboptimal ones. In contrast, the onset of absolute instability is delayed by varicose suboptimal perturbations and is slightly promoted by sinuous optimal ones. We show that if, instead of the computed fully nonlinear basic-flow distortions, the stability analysis is based on a shape assumption for the flow distortions, then opposite effects on the flow stability are predicted in most of the considered cases. These strong differences are attributed to the spanwise-uniform component of the nonlinear basic-flow distortion which, we conclude, should be systematically included in sensitivity analyses of the stability of two-dimensional basic flows to three-dimensional basic-flow perturbations. We finally show that the leading-order quadratic sensitivity of the eigenvalues to the amplitude of the streaks is preserved if the effects of the mean flow distortion are included in the sensitivity analysis.