I found in many text of QED dealing with scattering, the scattering matrix $S_{fi} \propto$ $\delta^4(p_f -p_i)$. They say that the $\delta$ function ensures the conservation of momentum and energy. But as we know from basic physics rule that energy is always conserved and momentum is conserved in some specialized cases. So we know in advance that at least energy is conserved. Hence in delta function $\delta(E_f -E_i)$ we can directly put $E_i = E_f$ and that will give infinitely large value. So how it conserve the energy. Also we can not not integrate it like $\int dE_f \delta(E_f -E_i)$ as $E_f = E_i$ always. I am just stuck with that please clarify it. Thanks