4. Given the quadratic function $y=a x^{2}(a \geqslant 1)$, the x-coordinates of points $A$ and $B$ on its graph are $-1, 2$, respectively, and $O$ is the origin. If $\triangle A O B$ is a right triangle, then the perimeter of $\triangle O A B$ is $\qquad$ .
$$
4.4 \sqrt{2}+2 \sqrt{5}
$$

As shown in Figure 6, $A(-1$, 
a), $B(2,4 a)$, then
$$
\begin{array}{l}
O A=\sqrt{a^{2}+1}, \\
O B=\sqrt{4+16 a^{2}}, \\
A B=\sqrt{9+9 a^{2}} .
\end{array}
$$

Since $a \geqslant 1$, $O A$ is the smallest side, so $O A$ cannot be the hypotenuse.
(i) If $O B$ is the hypotenuse, then $O B^{2}=O A^{2}+A B^{2}$. That is, 4 $+16 a^{2}=a^{2}+1+9+9 a^{2} \Rightarrow 6 a^{2}=6 \Rightarrow a^{2}=1 \Rightarrow a=1$ (since $a \geqslant 1) . The perimeter of $\triangle A O B$ is
$$
\sqrt{2}+\sqrt{20}+\sqrt{18}=4 \sqrt{2}+2 \sqrt{5} \text {. }
$$
(ii) If $A B$ is the hypotenuse, then $A B^{2}=O A^{2}+O B^{2}$. That is, 9 $+9 a^{2}=a^{2}+1+4+16 a^{2} \Rightarrow 8 a^{2}=4$. This does not meet the condition (since $a \geqslant$ 1).
Therefore, the perimeter of $\triangle A O B$ is $4 \sqrt{2}+2 \sqrt{5}$.