  In $d$-dimensional space (over any field), given a set of lines, a joint is a
point passed through by $d$ lines not all lying in some hyperplane. The joints
problem asks to determine the maximum number of joints formed by $L$ lines, and
it was one of the successes of the Guth--Katz polynomial method. We prove a new
upper bound on the number of joints that matches, up to a $1+o(1)$ factor, the
best known construction: place $k$ generic hyperplanes, and use their
$(d-1)$-wise intersections to form $\binom{k}{d-1}$ lines and their $d$-wise
intersections to form $\binom{k}{d}$ joints. Guth conjectured that this
construction is optimal. Our technique builds on the work on Ruixiang Zhang
proving the multijoints conjecture via an extension of the polynomial method.
We set up a variational problem to control the high order of vanishing of a
polynomial at each joint.
