4. Given a square $A B C D$ with side length $1, E$ is a point on side $A B$, and a line $E F \perp D E$ intersects $B C$ at point $F$. Then the maximum length of segment $B F$ is ( ).
(A) $\frac{1}{4}$
(B) $\frac{\sqrt{2}}{4}$
(C) $\frac{1}{2}$
(D) $\frac{\sqrt{2}}{2}$
4. A.

As shown in Figure 4, let $A E=x$.
Then $E B=1-x$.
It is easy to see that,
$$
\begin{array}{l} 
\triangle A D E \backsim \triangle B E F \\
\Rightarrow \frac{A E}{A D}=\frac{B F}{B E} \\
\Rightarrow B F=\frac{A E \cdot B E}{A D} \\
= x(1-x) \\
=-\left(x-\frac{1}{2}\right)^{2}+\frac{1}{4} \leqslant \frac{1}{4},
\end{array}
$$

When and only when $x=\frac{1}{2}$, i.e., $E$ is the midpoint of side $A B$, the length of segment $B F$ has a maximum value of $\frac{1}{4}$.