We show that for any subset $A\subset \F_2^n$ of density $\alpha>0$, there is a subspace $V\subseteq4A$ of codimension $O(\log^3(2/\alpha))$, and a subspace $V\subseteq 8A$ of codimension $O(\log^2(2/\alpha))$. This improves the previous bound of $O(\log^4(1/\alpha))$ due to Sanders (Analysis \& PDE 2012). The proof develops a stronger analytic property of almost periods of convolutions in total variation distance. We also show that this formulation of almost periodicity cannot give codimension $O(\log(1/\alpha))$ for any fixed number of convolutions, so it cannot by itself prove the polynomial Bogolyubov--Ruzsa conjecture.