We aim at computing time- and span-periodic flow fields in span-invariant configurations. The streamwise and cross-stream derivatives are discretised with finite volumes while time and the span-direction are handled with pseudo-spectral Fourier-collocation methods. Doing so, we extend the classical Time Spectral Method (TSM) to a Space–Time Spectral Method (S-TSM), by considering non-linear interactions of a finite number of time and span harmonics. For optimisation, we introduce an adjoint-based framework that allows efficient computation of the gradient of any cost functional with respect to a large-dimensional control parameter. Both theoretical and numerical aspects of the methodology are described: evaluation of matrix–vector products with S-TSM Jacobian (or its transpose) by algorithmic differentiation, solution of fixed-points with quasi-Newton method and de-aliasing in time and space, solution of direct and adjoint linear systems by iterative algorithms with a block-circulant preconditioner, performance assessment in CPU time and memory. We illustrate the methodology on the case of 3D instabilities (first Mack mode) triggered within a developing adiabatic boundary layer at M = 4.5. A gradient-ascent method allows to identify a finite-amplitude 3D forcing that triggers a non-linear response exhibiting the strongest time- and span-averaged drag on the flat-plate. In view of flow control, a gradient-descent method finally determines a finite amplitude 2D wall-heat flux that minimises the averaged drag of the plate in presence of the previously determined non-linear optimal forcing.