4. Given that $A D$ is the altitude of $\triangle A B C$,
$$
\angle B A C=135^{\circ}, A D=3, B C=25 \text {. }
$$

Then the perimeter of $\triangle A B C$ is $\qquad$ .
4. $30+15 \sqrt{2}$.

As shown in Figure 6, with point $A$ as the center and $AD$ as the radius, draw circle $\odot A$. Draw tangents to $\odot A$ from points $B$ and $C$, with the points of tangency being $E$ and $F$ respectively. The tangents intersect at point $G$, and connect $AE$ and $AF$. Let $BD=x$ and $CD=y$. Then
$$
BE=BD=x, \quad CF=CD=y.
$$

By the properties of the incenter,
$$
\begin{array}{l}
\angle BAC=90^{\circ}+\frac{1}{2} \angle BGC=135^{\circ} \\
\Rightarrow \angle BGC=90^{\circ}.
\end{array}
$$

Thus, quadrilateral $AEGF$ is a square.
Notice that
$$
\begin{array}{l}
BG=BE+EG=x+3, \\
CG=CF+FG=y+3.
\end{array}
$$

Then $BG^2 + CG^2 = BC^2$, i.e.,
$$
(x+3)^2 + (y+3)^2 = 25^2.
$$

Also, $x + y = 25$.
Solving equations (1) and (2) yields $(x, y) = (4, 21), (21, 4)$.
Therefore, the perimeter of $\triangle ABC$ is
$$
\begin{array}{l}
AB + AC + BC \\
= \sqrt{AD^2 + x^2} + \sqrt{AD^2 + y^2} + BC \\
= 5 + 15 \sqrt{2} + 25 = 30 + 15 \sqrt{2}.
\end{array}
$$