An exercise about a quantitative version of the Riemann-Lebesgue lemma As a follow-up to this question, I was wondering about

What is the supremum of the set of $A$ such that $I_n=\int_{0}^{1}\cos\left(\frac{1}{x}+nx\right)\,dx = O(n^{-A})$ as $n\to +\infty$ ?

We may notice that by considering the inverse function of $\frac{1}{x}+nx$ over $\left(0,\frac{1}{\sqrt{n}}\right)$ and $\left(\frac{1}{\sqrt{n}},1\right)$ we have
$$ I_n = -\frac{1}{2n}\int_{2\sqrt{n}}^{+\infty}\left(1-\frac{z}{\sqrt{z^2-4n}}\right)\cos(z)\,dz+\frac{1}{2n}\int_{2\sqrt{n}}^{n+1}\left(1+\frac{z}{\sqrt{z^2-4n}}\right)\cos(z)\,dz $$
where $\int_{2\sqrt{n}}^{+\infty}\left(1-\frac{z}{\sqrt{z^2-4n}}\right)\,dz = -2\sqrt{n}$ easily leads to $A\geq \frac{1}{2}$. Probably a combination of substitutions/integration by parts/inequalities for Bessel functions immediately solves this, but I am having a hard time in finding the correct approach.
 A: Let me settle the question. We may notice that
$$ \int_{0}^{1}\cos\left(\frac{1}{x}-nx\right)\,dx\qquad\text{and}\qquad\int_{0}^{1}\cos\left(\frac{1}{x}+nx\right)\,dx 
$$
have (somewhat surprisingly) a pretty different behaviour for $n\to +\infty$, the former being optimally bounded by $n^{-1}$ and the latter being optimally bounded by $n^{-\color{red}{3/4}}$. Indeed
$$ I_n = -\frac{2}{\sqrt{n}}\int_{1}^{+\infty}\left(1-\frac{z}{\sqrt{z^2-1}}\right)\cos(2\sqrt{n}x)\,dx+O\left(\frac{1}{n}\right) $$
equals
$$ -\frac{\pi}{\sqrt{n}} J_1(2\sqrt{n})+O\left(\frac{1}{n}\right) $$
where $J_1$ is the Bessel function
$$ J_1(z)=\sum_{n\geq 0}\frac{(-1)^n}{2\cdot 4^n n!(n+1)!}z^{2n+1} $$
fulfilling the differential equation
$$ z^2 f'' + z f' + (z^2-1) f = 0. $$
If we let $f(z)=\sqrt{z}\,g(z)$ the differential equation is transformed into
$$ g''(z) + \frac{2}{z} g'(z) + \left(1-\frac{3}{4z^2}\right) g(z) = 0 $$
whose solution is fairly close to a solution of $g''(z)+g(z)=0$. This leads to Tricomi's approximation
$$ J_1(z) \sim \frac{\sin(z)-\cos(z)}{\sqrt{\pi z}} \quad\text{for }z\to +\infty$$
and to the fact that the optimal bound for $I_n$ is $O(n^{-3/4})$ as conjectured.
