In Gamelin's Complex Analysis, there are exercises/examples (pg. 201-202) of the form
$$\int_{-\infty}^\infty \frac{P(x)}{Q(x)} \cos(ax) dx$$
The first "trick" is to use complex analysis: integrate along a semicircular contour consisting of the interval $[-R,R]$ on the real line, and then a semicircle $C_R$ going from $R$ to $iR$ to $-R$ (in the upper half plane). The next trick is that one should not integrate $\frac{P(z)}{Q(z )}\cos(az)$ (because $\cos(az)$ behaves very erratically along the semicircle; exponential growth on the imaginary axis, and tons of cancellation so no way of using the ML-estimate), but instead integrate $\frac{P(z)}{Q(z)}e^{iaz}$ and take the real part (because $|e^{iaz}|\leq 1$ on the upper half plane, so the ML-estimate shows that the integral along the semicircle goes to $0$ as $R\to\infty$).
As a corollary, we now know a lot about the integrals $$\int_{C_R} \frac{P(z)}{Q(z)} \cos(az) dz = \int_0^\pi \frac{P(R \cos t + iR \sin t)}{Q(R \cos t + iR \sin t)} (\cos(R\cos t)\cosh(R\sin t) - i\sin(R\cos t)\sinh(R \sin t)) dt,$$ which typically involve massive amounts of cancellation and thus are far beyond the power of the analyst's most useful inequality, the triangle inequality. For an explicit example, consider Gamelin's pg. 201 example $$\int_{-R}^R \frac{\cos ax}{1+x^2} dx = \frac{\pi}{e^a} + o(R)$$ for $a>0$; integrating $\frac{\cos az}{1+z^2}$, we get $$\int_{-R}^R \frac{\cos ax}{1+x^2} dx + \int_{C_R} \frac{\cos az}{1+z^2} dz = 2\pi i \cdot \operatorname{Res}\left[\frac{\cos az}{1+z^2}, i\right] = 2\pi i \cdot \left(-\frac 12 i \cosh(a)\right) = \pi \cosh(a),$$ implying that (notating $x=x(t)= R \cos(t)$ and $y=y(t)=R \sin(t)$) $$\int_{C_R} \frac{\cos az}{1+z^2} dz = \int_0^\pi \frac{(1+x^2-y^2)-2xyi}{(1+x^2-y^2)^2 + 4 x^2y^2}\cdot(\cos(ax)\cosh(ay)) - i\sin(ax)\sinh(ay))= \pi \cosh(a)-\frac{\pi}{e^a} + o(R),$$ or taking the real part $$\int_0^\pi \frac{(1+x^2-y^2) \cdot\cos(ax)\cosh(ay) - 2xy \cdot \sin(ax)\sinh(ay)}{(1+x^2-y^2)^2 + 4 x^2y^2} dt= \pi \cosh(a)-\frac{\pi}{e^a} + o(R)$$
Question 1: I wonder how difficult this integral really is. Maybe there is a simple $u$-substitution that unravels it, or some other (real-variable) technique. It would also be interesting to see if one could perform "Integral Milking", and milk this integral into some more pleasing (and perhaps even more difficult) piece of trivia.
It's rather amazing that via the "bridge" of extending $\cos x$ to either $\cos z$ or $\Re(e^{iz})$ (plus the Residue Theorem), one can transfer trivial results coming from the triangle inequality/ML-estimate for the latter, to extremely difficult results for the former (involving miraculous cancellation of hugely positive and hugely negative pieces to give a small but non-zero number --- this "delicate cancellation between two large terms" is reminiscent of the "Hierarchy Problem" in particle physics)
Main Question: do people know of any other integrals/any other methods that produces integrals like the one above/following this theme of "miraculous cancellation of hugely positive and hugely negative pieces to give a small but non-zero number"?
Another common integral where positive parts and negative parts cancel out perfectly is What is $\int_{-\pi}^\pi \cos(nx)\cos(mx)\,dx$? (i.e. cancellation comes from orthogonality of characters $e^{inx}$).
That MSE question had a "related questions" link that led to How to integrate $e^{r\cos x} \cos(r\sin x)$, which uses similar complex-analysis techniques to my example above to also find a value for an integral where massive cancellation occurs.
Some fields like Harmonic Analysis (and maybe fields like additive combinatorics/analytic number theory that use these harmonic analysis methods/themes/philosophies) really care about "exploiting cancellation" (see e.g. one of the most standard tools in this area, stationary/non-stationary phase), so I guess that's the philosophical motivation behind my interest in these sorts of integrals.
P.S. here's a Desmos link to some of the above massively-osscilating functions https://www.desmos.com/calculator/nx0zc5dxj7.